[cfe-commits] r144156 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/SemaCXX/constant-expression-cxx11.cpp

Richard Smith richard-llvm at metafoo.co.uk
Tue Nov 8 18:12:41 PST 2011


Author: rsmith
Date: Tue Nov  8 20:12:41 2011
New Revision: 144156

URL: http://llvm.org/viewvc/llvm-project?rev=144156&view=rev
Log:
Constant expression evaluation: support for default arguments.

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=144156&r1=144155&r2=144156&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Nov  8 20:12:41 2011
@@ -935,6 +935,8 @@
     { return StmtVisitorTy::Visit(E->getResultExpr()); }
   RetTy VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E)
     { return StmtVisitorTy::Visit(E->getReplacement()); }
+  RetTy VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E)
+    { return StmtVisitorTy::Visit(E->getExpr()); }
 
   RetTy VisitBinaryConditionalOperator(const BinaryConditionalOperator *E) {
     OpaqueValueEvaluation opaque(Info, E->getOpaqueValue(), E->getCommon());

Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=144156&r1=144155&r2=144156&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Tue Nov  8 20:12:41 2011
@@ -66,6 +66,36 @@
   static_assert_fold(wme.A == 42, "");
 }
 
+namespace DefaultArguments {
+
+const int z = int();
+constexpr int Sum(int a = 0, const int &b = 0, const int *c = &z, char d = 0) {
+  return a + b + *c + d;
+}
+const int four = 4;
+constexpr int eight = 8;
+constexpr const int twentyseven = 27;
+static_assert_fold(Sum() == 0, "");
+static_assert_fold(Sum(1) == 1, "");
+static_assert_fold(Sum(1, four) == 5, "");
+static_assert_fold(Sum(1, eight, &twentyseven) == 36, "");
+static_assert_fold(Sum(1, 2, &four, eight) == 15, "");
+
+}
+
+namespace Ellipsis {
+
+// Note, values passed through an ellipsis can't actually be used.
+constexpr int F(int a, ...) { return a; }
+static_assert_fold(F(0) == 0, "");
+static_assert_fold(F(1, 0) == 1, "");
+static_assert_fold(F(2, "test") == 2, "");
+static_assert_fold(F(3, &F) == 3, "");
+int k = 0;
+static_assert_fold(F(4, k) == 3, ""); // expected-error {{constant expression}}
+
+}
+
 namespace Recursion {
   constexpr int fib(int n) { return n > 1 ? fib(n-1) + fib(n-2) : n; }
   static_assert_fold(fib(11) == 89, "");





More information about the cfe-commits mailing list