]> granicus.if.org Git - clang/commitdiff
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224240 91177308-0d34-0410-b5e6-96231b3b80d8

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

index c04b99d464c34f36e688afb555cb3bf4121b9f9f..876e5b71e018fb23e5044b8584f5788107b4a244 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 5752f8f96631727579403bf81fd5d7b38b56c61d..fe9c719496986a23b9d30c5c0449fdecf2787119 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}}