r179068 - <rdar://problem/13584715> Converted constant expressions are expected to have integral values.

Douglas Gregor dgregor at apple.com
Mon Apr 8 16:24:07 PDT 2013


Author: dgregor
Date: Mon Apr  8 18:24:07 2013
New Revision: 179068

URL: http://llvm.org/viewvc/llvm-project?rev=179068&view=rev
Log:
<rdar://problem/13584715> Converted constant expressions are expected to have integral values.

We were assuming that any expression used as a converted constant
expression would either not have a folded constant value or would be
an integer, which is not the case for some ill-formed constant
expressions. Because converted constant expressions are only used
where integral values are expected, we can simply treat this as an
error path. If that ever changes, we'll need to widen the interface of
Sema::CheckConvertedConstantExpression() anyway.

Modified:
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=179068&r1=179067&r2=179068&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Mon Apr  8 18:24:07 2013
@@ -5024,7 +5024,7 @@ ExprResult Sema::CheckConvertedConstantE
   Expr::EvalResult Eval;
   Eval.Diag = &Notes;
 
-  if (!Result.get()->EvaluateAsRValue(Eval, Context)) {
+  if (!Result.get()->EvaluateAsRValue(Eval, Context) || !Eval.Val.isInt()) {
     // The expression can't be folded, so we can't keep it at this position in
     // the AST.
     Result = ExprError();

Modified: cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp?rev=179068&r1=179067&r2=179068&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp Mon Apr  8 18:24:07 2013
@@ -137,3 +137,19 @@ namespace DR1364 {
     return kGlobal; // expected-note {{read of non-const}}
   }
 }
+
+namespace rdar13584715 {
+  typedef __PTRDIFF_TYPE__ ptrdiff_t;
+  
+  template<typename T> struct X {
+    static T value() {};
+  };
+  
+  void foo(ptrdiff_t id) {
+    switch (id) {
+    case reinterpret_cast<ptrdiff_t>(&X<long>::value):  // expected-error{{case value is not a constant expression}} \
+      // expected-note{{reinterpret_cast is not allowed in a constant expression}}
+      break;
+    }
+  }
+}





More information about the cfe-commits mailing list