[PATCH] Fix PR18473 - Set NullType of ParenListExpr to Void (Similar to what's done for InitListExpr)
Faisal Vali
faisalv at yahoo.com
Sat Jan 18 15:10:39 PST 2014
Hi rsmith, doug.gregor,
http://llvm.org/bugs/show_bug.cgi?id=18473
A reduced case of this bug is as follows:
template <class T> void f()
{
static T x(1);
[]() -> T { return x; };
}
The fix is simply setting the type of the ParenListExpr to void - as is done for InitListExprs.
This way, when we analyze a lambda within a dependent context (i.e during the parsing and AST creation of the template itself) - and in our zeal to eagerly emit errors that we can diagnose even in the dependent context (such as diagnosing a variable that can never ever be - regardless of the instantiation - uncaptureable - so a lambda that can never capture a variable that must be captured, must be an error) and when we check if the initializer can never lead to a constant expression - we don't end up querying a NULLTYPE.
http://llvm-reviews.chandlerc.com/D2575
Files:
lib/Sema/SemaExpr.cpp
test/SemaCXX/PR18473.cpp
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -5247,6 +5247,7 @@
SourceLocation R,
MultiExprArg Val) {
Expr *expr = new (Context) ParenListExpr(Context, L, Val, R);
+ expr->setType(Context.VoidTy); // FIXME: just a place holder for now.
return Owned(expr);
}
Index: test/SemaCXX/PR18473.cpp
===================================================================
--- test/SemaCXX/PR18473.cpp
+++ test/SemaCXX/PR18473.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s -Wunused
+
+
+template < typename final_type >
+void direct_burr_impl()
+{
+ static const final_type l(1);
+
+ [](const final_type u) -> final_type { return -l + u; }; //expected-warning 4{{unused}}
+}
+
+int main()
+{
+ direct_burr_impl<int>(); //expected-note{{instantiation}}
+ direct_burr_impl<float>(); //expected-note{{instantiation}}
+ direct_burr_impl<double>(); //expected-note{{instantiation}}
+ direct_burr_impl<long double>(); //expected-note{{instantiation}}
+
+ return 0;
+}
+
+namespace reduced_case {
+
+template <class T>
+void f()
+{
+ static T x(1);
+ []() -> T { return x; };
+}
+
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2575.1.patch
Type: text/x-patch
Size: 1298 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140118/d57ea593/attachment.bin>
More information about the cfe-commits
mailing list