Clang error: deduction guide must be declared in the same scope as template A (err_deduction_guide_wrong_scope)
Jump to navigation
Jump to search
Text | error: deduction guide must be declared in the same scope as template A (since 5.0) |
---|---|
Type | Error |
Category | Semantic Issue (since 5.0) |
Internal Id | err_deduction_guide_wrong_scope (since 5.0) |
Internal Message | deduction guide must be declared in the same scope as template %q0 (since 5.0)
|
Regular Expression | (?:error|fatal error)\: deduction guide must be declared in the same scope as template (.*?)
|
First Commit | 2017-02-10 278890f85bba [c++1z] Enforce restriction that deduction guide is declared in the same scope as its template. |
Description
Example
Flags | -xc++
|
|
---|---|---|
Source |
// Deduction guide outside the namespace of its template
template <typename T> struct S { S(T); };
// Deduction guide in global scope
template <typename T> S(T) -> S<T>;
namespace N {
// Invalid: Deduction guide in different scope
template <typename T> S(T) -> S<T>;
}
| |
Compiler Output |
<source>:10:27: error: deduction guide must be declared in the same scope as template 'S' <source>:3:30: note: template is declared here |
Clang Internals (17.0.6)
Git Commit Message
[c++1z] Enforce restriction that deduction guide is declared in the same scope as its template. llvm-svn: 294778
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 11235)
/// Check the validity of a declarator that we parsed for a deduction-guide.
/// These aren't actually declarators in the grammar, so we need to check that
/// the user didn't specify any pieces that are not part of the deduction-guide
/// grammar. Return true on invalid deduction-guide.
bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R, StorageClass &SC) {
// ...
// C++ [temp.deduct.guide]p3:
// A deduction-gide shall be declared in the same scope as the
// corresponding class template.
if (!CurContext->getRedeclContext()->Equals(GuidedTemplateDecl->getDeclContext()->getRedeclContext())) {
Diag(D.getIdentifierLoc(), diag::err_deduction_guide_wrong_scope) << GuidedTemplateDecl;
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/CXX/temp/temp.deduct.guide/p3.cpp
- clang/test/CXX/temp/temp.deduct.guide/p3.cpp:46:3: error: deduction guide must be declared in the same scope as template 'WrongScope::(anonymous namespace)::AnonNS1'
- clang/test/CXX/temp/temp.deduct.guide/p3.cpp:50:5: error: deduction guide must be declared in the same scope as template 'WrongScope::AnonNS2'
- clang/test/CXX/temp/temp.deduct.guide/p3.cpp:57:3: error: deduction guide must be declared in the same scope as template 'WrongScope::N::NamedNS1'
- clang/test/CXX/temp/temp.deduct.guide/p3.cpp:60:3: error: deduction guide must be declared in the same scope as template 'WrongScope::N::NamedNS2'
- clang/test/CXX/temp/temp.deduct.guide/p3.cpp:65:5: error: deduction guide must be declared in the same scope as template 'WrongScope::ClassMemberA::X'