Clang warning: use of this statement in a constexpr ... is a C++14 extension [-Wc++14-extensions] (ext_constexpr_body_invalid_stmt)
Jump to navigation
Jump to search
Text |
| ||||||
---|---|---|---|---|---|---|---|
Type | Warning | ||||||
Category | Semantic Issue | ||||||
Internal Id | ext_constexpr_body_invalid_stmt | ||||||
Active by Default | Yes | ||||||
Flags | -Wno-c++14-extensions (9 elements) -Wno-c++1y-extensions (9 elements) | ||||||
Internal Message | use of this statement in a constexpr %select{function|constructor}0 is a C++14 extension
| ||||||
Regular Expression | (?:warning|error|fatal error)\: use of this statement in a constexpr (?:function|constructor) is a C\+\+14 extension \[(?:\-Werror,)?\-Wc\+\+14\-extensions[^\]]*\]
| ||||||
First Commit | 2013-04-22 d9f663b510c4 C++1y constexpr extensions, round 1: Allow most forms of declaration and |
Description
Example
Flags | -xc++ -std=c++11
|
|
---|---|---|
Source |
#include <iostream>
constexpr int f(bool b) {
// if statement
if (b)
return 10;
else
return 20;
}
int main() {
std::cout << f(true) << std::endl;
return 0;
}
| |
Compiler Output |
<source>:5:3: warning: use of this statement in a constexpr function is a C++14 extension [-Wc++14-extensions] <source>:8:5: warning: multiple return statements in constexpr function is a C++14 extension [-Wc++14-extensions] <source>:6:5: note: previous return statement is here |
Clang Internals (17.0.6)
Git Commit Message
C++1y constexpr extensions, round 1: Allow most forms of declaration and statement in constexpr functions. Everything which doesn't require variable mutation is also allowed as an extension in C++11. 'void' becomes a literal type to support constexpr functions which return 'void'. llvm-svn: 180022
Used in Clang Sources
This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.
clang/lib/Sema/SemaDeclCXX.cpp (line 2300)
/// Check the body for the given constexpr function declaration only contains
/// the permitted types of statement. C++11 [dcl.constexpr]p3,p4.
///
/// \return true if the body is OK, false if we have found or diagnosed a
/// problem.
static bool CheckConstexprFunctionBody(Sema &SemaRef, const FunctionDecl *Dcl, Stmt *Body, Sema::CheckConstexprKind Kind) {
// ...
if (Kind == Sema::CheckConstexprKind::CheckValid) {
// ...
} else if (Cxx2bLoc.isValid()) {
// ...
} else if (Cxx2aLoc.isValid()) {
// ...
} else if (Cxx1yLoc.isValid()) {
SemaRef.Diag(Cxx1yLoc, SemaRef.getLangOpts().CPlusPlus14 ? diag::warn_cxx11_compat_constexpr_body_invalid_stmt : diag::ext_constexpr_body_invalid_stmt) << isa<CXXConstructorDecl>(Dcl);
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
- clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp:57:11: error: use of this statement in a constexpr constructor is a C++14 extension [-Werror,-Wc++14-extensions]
- clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp:106:5: error: use of this statement in a constexpr constructor is a C++14 extension [-Werror,-Wc++14-extensions]
- clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp:130:5: error: use of this statement in a constexpr constructor is a C++14 extension [-Werror,-Wc++14-extensions]