[cfe-commits] r164968 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/SemaCXX/constant-expression-cxx11.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Mon Oct 1 13:36:18 PDT 2012
Author: rsmith
Date: Mon Oct 1 15:36:17 2012
New Revision: 164968
URL: http://llvm.org/viewvc/llvm-project?rev=164968&view=rev
Log:
Fix treatment of case which came up on std-proposals@: 'void' is permitted in core constant expressions, despite not being a literal type.
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=164968&r1=164967&r2=164968&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Oct 1 15:36:17 2012
@@ -6196,11 +6196,9 @@
return false;
Result = Info.CurrentCall->Temporaries[E];
} else if (E->getType()->isVoidType()) {
- if (Info.getLangOpts().CPlusPlus0x)
+ if (!Info.getLangOpts().CPlusPlus0x)
Info.CCEDiag(E, diag::note_constexpr_nonliteral)
<< E->getType();
- else
- Info.CCEDiag(E, diag::note_invalid_subexpr_in_const_expr);
if (!EvaluateVoid(E, Info))
return false;
} else if (Info.getLangOpts().CPlusPlus0x) {
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=164968&r1=164967&r2=164968&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Mon Oct 1 15:36:17 2012
@@ -1390,3 +1390,21 @@
constexpr int *g() { return &m; }
constexpr int *r = g();
}
+
+namespace Void {
+ constexpr void f() { return; } // expected-error{{constexpr function's return type 'void' is not a literal type}}
+
+ void assert_failed(const char *msg, const char *file, int line); // expected-note {{declared here}}
+#define ASSERT(expr) ((expr) ? static_cast<void>(0) : assert_failed(#expr, __FILE__, __LINE__))
+ template<typename T, size_t S>
+ constexpr T get(T (&a)[S], size_t k) {
+ return ASSERT(k > 0 && k < S), a[k]; // expected-note{{non-constexpr function 'assert_failed'}}
+ }
+#undef ASSERT
+ template int get(int (&a)[4], size_t);
+ constexpr int arr[] = { 4, 1, 2, 3, 4 };
+ static_assert(get(arr, 1) == 1, "");
+ static_assert(get(arr, 4) == 4, "");
+ static_assert(get(arr, 0) == 4, ""); // expected-error{{not an integral constant expression}} \
+ // expected-note{{in call to 'get(arr, 0)'}}
+}
More information about the cfe-commits
mailing list