]> granicus.if.org Git - clang/commitdiff
Consistently use a ConstantEvaluated context for expressions in attributes,
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 7 Jan 2017 19:42:26 +0000 (19:42 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 7 Jan 2017 19:42:26 +0000 (19:42 +0000)
except for those with the "attributes are unevaluated contexts" flag.

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

lib/Parse/ParseDecl.cpp
lib/Sema/SemaTemplateInstantiateDecl.cpp
test/SemaCXX/enable_if.cpp

index ba24adefe6b0215586a55b02eb762b451a01ff8d..833d93e4548ae43ae01da8ee682f1cc7e963ecfe 100644 (file)
@@ -306,10 +306,11 @@ unsigned Parser::ParseAttributeArgsCommon(
 
     // Parse the non-empty comma-separated list of expressions.
     do {
-      bool ShouldEnter = attributeParsedArgsUnevaluated(*AttrName);
+      bool Uneval = attributeParsedArgsUnevaluated(*AttrName);
       EnterExpressionEvaluationContext Unevaluated(
-          Actions, Sema::Unevaluated, /*LambdaContextDecl=*/nullptr,
-          /*IsDecltype=*/false, ShouldEnter);
+          Actions, Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated,
+          /*LambdaContextDecl=*/nullptr,
+          /*IsDecltype=*/false);
 
       ExprResult ArgExpr(
           Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()));
index f4013b82064180faa1c9619b5e22e4ba1aebc283..e7679fc11e23f85b132870be2e5f54d0fd36e178 100644 (file)
@@ -173,7 +173,8 @@ static void instantiateDependentEnableIfAttr(
     const EnableIfAttr *A, const Decl *Tmpl, Decl *New) {
   Expr *Cond = nullptr;
   {
-    EnterExpressionEvaluationContext Unevaluated(S, Sema::Unevaluated);
+    ContextRAII SwitchContext(*this, cast<FunctionDecl>(New));
+    EnterExpressionEvaluationContext Unevaluated(S, Sema::ConstantEvaluated);
     ExprResult Result = S.SubstExpr(A->getCond(), TemplateArgs);
     if (Result.isInvalid())
       return;
index 0f8fc9b2652abbb0635f4dc8a13d0bd83cf984a3..eababc34d3702545c1ecc3a62fd19d9d2c861510 100644 (file)
@@ -464,3 +464,11 @@ void runFoo() {
   Foo<double>().bar(1);
 }
 }
+
+namespace instantiate_constexpr_in_enable_if {
+  template<typename T> struct X {
+    static constexpr bool ok() { return true; }
+    void f() __attribute__((enable_if(ok(), "")));
+  };
+  void g() { X<int>().f(); }
+}