Clang error: 'using_if_exists' attribute cannot be applied to an inheriting constructor (err_using_if_exists_on_ctor)
Jump to navigation
Jump to search
Text | error: 'using_if_exists' attribute cannot be applied to an inheriting constructor (since 13.0) |
---|---|
Type | Error |
Category | Semantic Issue (since 13.0) |
Internal Id | err_using_if_exists_on_ctor (since 13.0) |
Internal Message | 'using_if_exists' attribute cannot be applied to an inheriting constructor (since 13.0)
|
Regular Expression | (?:error|fatal error)\: 'using_if_exists' attribute cannot be applied to an inheriting constructor
|
First Commit | 2021-03-10 3dbcea8b957a Reland [clang] Check unsupported types in expressions |
Description
Example
Flags | -xc++
|
|
---|---|---|
Source |
#include <utility>
struct B {};
struct D : B {
// Invalid use of 'using_if_exists' on inheriting constructor
using B::B [[clang::using_if_exists]];
};
| |
Compiler Output |
<source>:7:18: warning: ISO C++ does not allow an attribute list to appear here [-Wcxx-attribute-extension] <source>:7:5: error: 'using_if_exists' attribute cannot be applied to an inheriting constructor |
Clang Internals (17.0.6)
Git Commit Message
Reland [clang] Check unsupported types in expressions This was committed as ec6c847179fd, but then reverted after a failure in: https://lab.llvm.org/buildbot/#/builders/84/builds/13983 I was not able to reproduce the problem, but I added an extra check for a NULL QualType just in case. Original comit message: The patch adds missing diagnostics for cases like: float F3 = ((__float128)F1 * (__float128)F2) / 2.0f; Sema::checkDeviceDecl (renamed to checkTypeSupport) is changed to work with a type without the corresponding ValueDecl. It is also refactored so that host diagnostics for unsupported types can be added here as well. Differential Revision: https://reviews.llvm.org/D109315
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 12624)
/// Builds a using declaration.
///
/// \param IsInstantiation - Whether this call arises from an
/// instantiation of an unresolved using declaration. We treat
/// the lookup differently for these declarations.
NamedDecl *Sema::BuildUsingDeclaration(Scope *S, AccessSpecifier AS, SourceLocation UsingLoc, bool HasTypenameKeyword, SourceLocation TypenameLoc, CXXScopeSpec &SS, DeclarationNameInfo NameInfo, SourceLocation EllipsisLoc, const ParsedAttributesView &AttrList, bool IsInstantiation, bool IsUsingIfExists) {
// ...
// 'using_if_exists' doesn't make sense on an inherited constructor.
if (IsUsingIfExists && UsingName.getName().getNameKind() == DeclarationName::CXXConstructorName) {
Diag(UsingLoc, diag::err_using_if_exists_on_ctor);
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/SemaCXX/using-if-exists.cpp
- clang/test/SemaCXX/using-if-exists.cpp:66:3: error: 'using_if_exists' attribute cannot be applied to an inheriting constructor