From 69e6d608610f9a6d8841dbcf2cacae543ee7a25d Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Mon, 15 Dec 2014 10:00:35 +0000 Subject: [PATCH] Sema: Don't diagnose string + int if the int is value dependent 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 | 2 +- test/SemaCXX/string-plus-int.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index c04b99d464..876e5b71e0 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -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; diff --git a/test/SemaCXX/string-plus-int.cpp b/test/SemaCXX/string-plus-int.cpp index 5752f8f966..fe9c719496 100644 --- a/test/SemaCXX/string-plus-int.cpp +++ b/test/SemaCXX/string-plus-int.cpp @@ -64,3 +64,8 @@ void f(int index) { consume(A B + sizeof(A) - 1); } +template +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(); // expected-note {{in instantiation of function template specialization 'PR21848' requested here}} -- 2.50.1