]> granicus.if.org Git - clang/commitdiff
PR33318: Add missing full-expression checking to static_assert expression.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 6 Jun 2017 01:34:24 +0000 (01:34 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 6 Jun 2017 01:34:24 +0000 (01:34 +0000)
This fixes missing lambda-captures for variables referenced only inside a
static_assert (!), among other things.

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

include/clang/Parse/Parser.h
lib/Parse/ParseDeclCXX.cpp
lib/Sema/SemaDeclCXX.cpp
test/SemaCXX/cxx1y-generic-lambdas-capturing.cpp
test/SemaTemplate/deduction.cpp

index f4d5a661bd7228a5527a08ad625b5df677e1feea..a51d3a51d435e7e1fbe3ca55acd902bbcc12400b 100644 (file)
@@ -1461,7 +1461,8 @@ public:
   };
 
   ExprResult ParseExpression(TypeCastState isTypeCast = NotTypeCast);
-  ExprResult ParseConstantExpressionInExprEvalContext(TypeCastState isTypeCast);
+  ExprResult ParseConstantExpressionInExprEvalContext(
+      TypeCastState isTypeCast = NotTypeCast);
   ExprResult ParseConstantExpression(TypeCastState isTypeCast = NotTypeCast);
   ExprResult ParseConstraintExpression();
   // Expr that doesn't include commas.
index 4c117f531ef143ec839019848a3dbcb009970c81..1a4607a84cff26471f29eba6bb2c71f8f946af13 100644 (file)
@@ -840,7 +840,9 @@ Decl *Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd){
     return nullptr;
   }
 
-  ExprResult AssertExpr(ParseConstantExpression());
+  EnterExpressionEvaluationContext ConstantEvaluated(
+      Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
+  ExprResult AssertExpr(ParseConstantExpressionInExprEvalContext());
   if (AssertExpr.isInvalid()) {
     SkipMalformedDecl();
     return nullptr;
index acacdc263c0811f6210b3f838e8842d2d38dac41..3e2306361cd83e60dadec5950e83adc30c4f2511 100644 (file)
@@ -13232,6 +13232,14 @@ Decl *Sema::BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc,
     }
   }
 
+  ExprResult FullAssertExpr = ActOnFinishFullExpr(AssertExpr, StaticAssertLoc,
+                                                  /*DiscardedValue*/false,
+                                                  /*IsConstexpr*/true);
+  if (FullAssertExpr.isInvalid())
+    Failed = true;
+  else
+    AssertExpr = FullAssertExpr.get();
+
   Decl *Decl = StaticAssertDecl::Create(Context, CurContext, StaticAssertLoc,
                                         AssertExpr, AssertMessage, RParenLoc,
                                         Failed);
index b08d58abd2a9c3dedb590b76068427a95fdec868..dc3adca62fd365adc1f10d20d88835d45ef42b33 100644 (file)
@@ -1376,3 +1376,7 @@ XT<int> xt{};
 
 
 }
+
+void PR33318(int i) {
+  [&](auto) { static_assert(&i != nullptr, ""); }(0); // expected-warning 2{{always true}} expected-note {{instantiation}}
+}
index 74eb5a6ee58192d4a3bf7fec5770cd4414a4b1a7..be86f18729dc26b238d6a8e126d0278e5b063340 100644 (file)
@@ -305,11 +305,11 @@ namespace nullptr_deduction {
 
   template<typename T, T v> struct X {};
   template<typename T, T v> void f(X<T, v>) {
-    static_assert(!v, "");
+    static_assert(!v, ""); // expected-warning 2{{implicit conversion of nullptr constant to 'bool'}}
   }
   void g() {
-    f(X<int*, nullptr>());
-    f(X<nullptr_t, nullptr>());
+    f(X<int*, nullptr>()); // expected-note {{instantiation of}}
+    f(X<nullptr_t, nullptr>()); // expected-note {{instantiation of}}
   }
 
   template<template<typename T, T> class X, typename T, typename U, int *P>