From 0c6124ba82063b05b9c85b63bb29ec354aa1be0b Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 3 Dec 2015 01:36:22 +0000 Subject: PR17381: Treat undefined behavior during expression evaluation as an unmodeled side-effect, so that we don't allow speculative evaluation of such expressions during code generation. This caused a diagnostic quality regression, so fix constant expression diagnostics to prefer either the first "can't be constant folded" diagnostic or the first "not a constant expression" diagnostic depending on the kind of evaluation we're doing. This was always the intent, but didn't quite work correctly before. This results in certain initializers that used to be constant initializers to no longer be; in particular, things like: float f = 1e100; are no longer accepted in C. This seems appropriate, as such constructs would lead to code being executed if sanitizers are enabled. llvm-svn: 254574 --- clang/test/SemaCXX/constexpr-printing.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'clang/test/SemaCXX/constexpr-printing.cpp') diff --git a/clang/test/SemaCXX/constexpr-printing.cpp b/clang/test/SemaCXX/constexpr-printing.cpp index e545f45d601..7f6a9c6a82f 100644 --- a/clang/test/SemaCXX/constexpr-printing.cpp +++ b/clang/test/SemaCXX/constexpr-printing.cpp @@ -90,10 +90,12 @@ constexpr wchar_t wc = get(L"test\0\\\"\t\a\b\234\u1234\xffffffff"); // \ constexpr char32_t c32_err = get(U"\U00110000"); // expected-error {{invalid universal character}} +#define fold(x) (__builtin_constant_p(x) ? (x) : (x)) + typedef decltype(sizeof(int)) LabelDiffTy; constexpr LabelDiffTy mulBy3(LabelDiffTy x) { return x * 3; } // expected-note {{subexpression}} void LabelDiffTest() { - static_assert(mulBy3((LabelDiffTy)&&a-(LabelDiffTy)&&b) == 3, ""); // expected-error {{constant expression}} expected-note {{call to 'mulBy3(&&a - &&b)'}} + static_assert(mulBy3(fold((LabelDiffTy)&&a-(LabelDiffTy)&&b)) == 3, ""); // expected-error {{constant expression}} expected-note {{call to 'mulBy3(&&a - &&b)'}} a:b:return; } -- cgit v1.2.3