Sema: Don't diagnose string + int if the int is value dependent
authorDavid Majnemer <david.majnemer@gmail.com>
Mon, 15 Dec 2014 10:00:35 +0000 (10:00 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Mon, 15 Dec 2014 10:00:35 +0000 (10:00 +0000)
Don't send a value dependent expression into the expression evaluator,
HandleSizeof would crash.  Making HandleSizeof handle dependent types
would noisily warn about the operation even if everything turns out OK
after instantiation.

This fixes PR21848.

llvm-svn: 224240

clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/string-plus-int.cpp

index c04b99d..876e5b7 100644 (file)
@@ -7282,7 +7282,7 @@ static void diagnoseStringPlusInt(Sema &Self, SourceLocation OpLoc,
 
   bool IsStringPlusInt = StrExpr &&
       IndexExpr->getType()->isIntegralOrUnscopedEnumerationType();
-  if (!IsStringPlusInt)
+  if (!IsStringPlusInt || IndexExpr->isValueDependent())
     return;
 
   llvm::APSInt index;
index 5752f8f..fe9c719 100644 (file)
@@ -64,3 +64,8 @@ void f(int index) {
   consume(A B + sizeof(A) - 1);
 }
 
+template <typename T>
+void PR21848() {
+  (void)(sizeof(T) + ""); // expected-warning {{to a string does not append to the string}} expected-note {{use array indexing to silence this warning}}
+}
+template void PR21848<int>(); // expected-note {{in instantiation of function template specialization 'PR21848<int>' requested here}}