Clang warning: explicit(bool) is a C++20 extension [-Wc++20-extensions] (ext_explicit_bool)
Jump to navigation
Jump to search
Text | error: explicit(bool) is a C++20 extension (since 10.0) |
---|---|
Type | Warning |
Category | Parse Issue (since 10.0) |
Internal Id | ext_explicit_bool (since 10.0) |
Active by Default | Yes |
Flags | -Wno-c++20-extensions (23 elements) -Wno-c++2a-extensions (23 elements) |
Internal Message | explicit(bool) is a C++20 extension (since 10.0)
|
Regular Expression | (?:warning|error|fatal error)\: explicit\(bool\) is a C\+\+20 extension \[(?:\-Werror,)?\-Wc\+\+20\-extensions[^\]]*\]
|
First Commit | 2019-10-09 739b410f1ff5 Add a warning, flags and pragmas to limit the number of pre-processor tokens in a translation unit |
Description
Example
Flags | -xc++ -std=c++17 -Wc++20-extensions
|
|
---|---|---|
Source |
// C++17 code
struct S {
// C++20 feature used
explicit(false) S(int) {}
};
| |
Compiler Output |
<source>:4:11: warning: explicit(bool) is a C++20 extension [-Wc++20-extensions] |
Clang Internals (17.0.6)
Git Commit Message
Add a warning, flags and pragmas to limit the number of pre-processor tokens in a translation unit See https://docs.google.com/document/d/1xMkTZMKx9llnMPgso0jrx3ankI4cv60xeZ0y4ksf4wc/preview for background discussion. This adds a warning, flags and pragmas to limit the number of pre-processor tokens either at a certain point in a translation unit, or overall. The idea is that this would allow projects to limit the size of certain widely included headers, or for translation units overall, as a way to insert backstops for header bloat and prevent compile-time regressions. Differential revision: https://reviews.llvm.org/D72703
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/Parse/ParseDecl.cpp (line 4047)
/// ParseDeclarationSpecifiers
/// declaration-specifiers: [C99 6.7]
/// storage-class-specifier declaration-specifiers[opt]
/// type-specifier declaration-specifiers[opt]
/// [C99] function-specifier declaration-specifiers[opt]
/// [C11] alignment-specifier declaration-specifiers[opt]
/// [GNU] attributes declaration-specifiers[opt]
/// [Clang] '__module_private__' declaration-specifiers[opt]
/// [ObjC1] '__kindof' declaration-specifiers[opt]
///
/// storage-class-specifier: [C99 6.7.1]
/// 'typedef'
/// 'extern'
/// 'static'
/// 'auto'
/// 'register'
/// [C++] 'mutable'
/// [C++11] 'thread_local'
/// [C11] '_Thread_local'
/// [GNU] '__thread'
/// function-specifier: [C99 6.7.4]
/// [C99] 'inline'
/// [C++] 'virtual'
/// [C++] 'explicit'
/// [OpenCL] '__kernel'
/// 'friend': [C++ dcl.friend]
/// 'constexpr': [C++0x dcl.constexpr]
void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, const ParsedTemplateInfo &TemplateInfo, AccessSpecifier AS, DeclSpecContext DSContext, LateParsedAttrList *LateAttrs, ImplicitTypenameContext AllowImplicitTypename) {
// ...
while (true) {
// ...
case tok::kw_explicit: {
// ...
if (Tok.is(tok::l_paren)) {
if (getLangOpts().CPlusPlus20 || isExplicitBool() == TPResult::True) {
Diag(Tok.getLocation(), getLangOpts().CPlusPlus20 ? diag::warn_cxx17_compat_explicit_bool : diag::ext_explicit_bool);
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/Parser/explicit-bool.cpp
- clang/test/Parser/explicit-bool.cpp:47:12: warning: explicit(bool) is a C++20 extension [-Wc++20-extensions]
- clang/test/Parser/explicit-bool.cpp:52:12: warning: explicit(bool) is a C++20 extension [-Wc++20-extensions]