]> granicus.if.org Git - clang/commitdiff
Print 'int' instead of 'const int' in the narrowing conversion error, since the
authorJeffrey Yasskin <jyasskin@google.com>
Mon, 29 Aug 2011 15:59:37 +0000 (15:59 +0000)
committerJeffrey Yasskin <jyasskin@google.com>
Mon, 29 Aug 2011 15:59:37 +0000 (15:59 +0000)
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

lib/Sema/SemaInit.cpp
test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp

index 2d47cda0e0f43dab0ba5a1d71ff8ac74cec87f14..7a6134453b5f67001c7b3c1912fcee1512c625c6 100644 (file)
@@ -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);
index c7f61fbd1882398b106dfaa204e5b307bd5d95d0..be47cb8fe86ee9a356c96c9e3f7babf9991d814a 100644 (file)
@@ -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<const unsigned char> c2 = {j};  // expected-error {{from type 'int' to 'const unsigned char' in}} expected-note {{override}}
+}