r224240 - Sema: Don't diagnose string + int if the int is value dependent
David Majnemer
david.majnemer at gmail.com
Mon Dec 15 02:00:35 PST 2014
Author: majnemer
Date: Mon Dec 15 04:00:35 2014
New Revision: 224240
URL: http://llvm.org/viewvc/llvm-project?rev=224240&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaCXX/string-plus-int.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=224240&r1=224239&r2=224240&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Dec 15 04:00:35 2014
@@ -7282,7 +7282,7 @@ static void diagnoseStringPlusInt(Sema &
bool IsStringPlusInt = StrExpr &&
IndexExpr->getType()->isIntegralOrUnscopedEnumerationType();
- if (!IsStringPlusInt)
+ if (!IsStringPlusInt || IndexExpr->isValueDependent())
return;
llvm::APSInt index;
Modified: cfe/trunk/test/SemaCXX/string-plus-int.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/string-plus-int.cpp?rev=224240&r1=224239&r2=224240&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/string-plus-int.cpp (original)
+++ cfe/trunk/test/SemaCXX/string-plus-int.cpp Mon Dec 15 04:00:35 2014
@@ -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}}
More information about the cfe-commits
mailing list