From: Jeffrey Yasskin Date: Mon, 29 Aug 2011 15:59:37 +0000 (+0000) Subject: Print 'int' instead of 'const int' in the narrowing conversion error, since the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9906149972906e340f512a60f72a8676748f24d8;p=clang Print 'int' instead of 'const int' in the narrowing conversion error, since the qualification of a type doesn't affect whether a conversion is a narrowing conversion. This doesn't work in template cases because SubstTemplateTypeParmType gets in the way. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138735 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 2d47cda0e0..7a6134453b 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -5168,15 +5168,15 @@ static void DiagnoseNarrowingInInitList( : diag::warn_init_list_constant_narrowing) << InitE->getSourceRange() << ConstantValue - << EntityType; + << EntityType.getLocalUnqualifiedType(); } else S.Diag(InitE->getLocStart(), S.getLangOptions().CPlusPlus0x && !S.getLangOptions().Microsoft ? diag::err_init_list_variable_narrowing : diag::warn_init_list_variable_narrowing) << InitE->getSourceRange() - << InitE->getType() - << EntityType; + << InitE->getType().getLocalUnqualifiedType() + << EntityType.getLocalUnqualifiedType(); llvm::SmallString<128> StaticCast; llvm::raw_svector_ostream OS(StaticCast); diff --git a/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp b/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp index c7f61fbd18..be47cb8fe8 100644 --- a/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp +++ b/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp @@ -160,3 +160,13 @@ void test_template() { maybe_shrink_int<15>((int)3); // expected-note {{in instantiation}} maybe_shrink_int<70000>((char)3); // expected-note {{in instantiation}} } + + +// We don't want qualifiers on the types in the diagnostic. + +void test_qualifiers(int i) { + const int j = i; + struct {const unsigned char c;} c1 = {j}; // expected-error {{from type 'int' to 'unsigned char' in}} expected-note {{override}} + // Template arguments make it harder to avoid printing qualifiers: + Agg c2 = {j}; // expected-error {{from type 'int' to 'const unsigned char' in}} expected-note {{override}} +}