diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 8afa3324661800303f1efd11f89e111b850e75c8..9c08495286c8fec72313898715de0ad85aadffaf 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -1230,9 +1230,9 @@ bool Sema::CheckConstexprFunctionBody(const FunctionDecl *Dcl, Stmt *Body) { Diag(Dcl->getLocation(), OK ? diag::warn_cxx11_compat_constexpr_body_no_return : diag::err_constexpr_body_no_return); - return OK; - } - if (ReturnStmts.size() > 1) { + if (!OK) + return false; + } else if (ReturnStmts.size() > 1) { Diag(ReturnStmts.back(), getLangOpts().CPlusPlus14 ? diag::warn_cxx11_compat_constexpr_body_multiple_return diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p5.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p5.cpp index 48973237ea0b1804bd55b21677237da1c428a1fe..18b2c6b1d6d15b69a4e678da5eb293dade9fd0cd 100644 --- a/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p5.cpp +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p5.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown -verify -std=c++11 -fcxx-exceptions %s +// RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown -verify -std=c++14 -fcxx-exceptions %s // RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown -std=c++11 -fcxx-exceptions -Wno-invalid-constexpr %s -DNO_INVALID_CONSTEXPR namespace StdExample { @@ -102,7 +103,10 @@ X x = cmin(X(), X()); // ok, not constexpr template<typename T> struct Y { constexpr Y() {} - constexpr int get() { return T(); } // expected-warning {{C++14}} + constexpr int get() { return T(); } +#if __cplusplus < 201402L + // expected-warning@-2 {{C++14}} +#endif }; struct Z { operator int(); }; @@ -118,7 +122,7 @@ namespace PR14550 { // marks some functions as constexpr which use builtins which we don't // support constant folding). Ensure that we don't mark those functions // as invalid after suppressing the diagnostic. -# 122 "p5.cpp" 1 3 +# 126 "p5.cpp" 1 3 int n; struct A { static constexpr int f() { return n; } @@ -126,7 +130,11 @@ namespace PR14550 { template<typename T> struct B { B() { g(T::f()); } // expected-error {{undeclared identifier 'g'}} }; -# 130 "p5.cpp" 2 +# 134 "p5.cpp" 2 template class B<A>; // expected-note {{here}} } #endif + +#if __cplusplus >= 201402L +constexpr void f() { throw; } // expected-error {{never produces}} expected-note {{subexpression}} +#endif