Clang error: default argument not permitted on an explicit ... of function B (err_template_spec_default_arg)
Jump to navigation
Jump to search
Text |
| ||||||
---|---|---|---|---|---|---|---|
Type | Error | ||||||
Category | Semantic Issue | ||||||
Internal Id | err_template_spec_default_arg | ||||||
Internal Message | default argument not permitted on an explicit %select{instantiation|specialization}0 of function %1
| ||||||
Regular Expression | (?:error|fatal error)\: default argument not permitted on an explicit (?:instantiation|specialization) of function (.*?)
| ||||||
First Commit | 2009-10-13 62e10f0bdcaa Diagnose attempts to add default function arguments to a |
Description
Example
Flags | -xc++ -std=c++17
|
|
---|---|---|
Source |
template <typename T> void f(T t); // template declaration
template <> void f<int>(int t = 0); // explicit specialization with default argument
| |
Compiler Output |
<source>:3:29: error: default argument not permitted on an explicit specialization of function 'f' |
Clang Internals (17.0.6)
Git Commit Message
Diagnose attempts to add default function arguments to a specialization. This completes C++ [temp.expl.spec]! llvm-svn: 83980
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 617)
/// MergeCXXFunctionDecl - Merge two declarations of the same C++
/// function, once we already know that they have the same
/// type. Subroutine of MergeFunctionDecl. Returns true if there was an
/// error, false otherwise.
bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S) {
// ...
// C++ [dcl.fct.default]p4:
// For non-template functions, default arguments can be added in
// later declarations of a function in the same
// scope. Declarations in different scopes have completely
// distinct sets of default arguments. That is, declarations in
// inner scopes do not acquire default arguments from
// declarations in outer scopes, and vice versa. In a given
// function declaration, all parameters subsequent to a
// parameter with a default argument shall have default
// arguments supplied in this or previous declarations. A
// default argument shall not be redefined by a later
// declaration (not even to the same value).
//
// C++ [dcl.fct.default]p6:
// Except for member functions of class templates, the default arguments
// in a member function definition that appears outside of the class
// definition are added to the set of default arguments provided by the
// member function declaration in the class definition.
for (unsigned p = 0, NumParams = PrevForDefaultArgs ? PrevForDefaultArgs->getNumParams() : 0; p < NumParams; ++p) {
// ...
if (OldParamHasDfl && NewParamHasDfl) {
// ...
} else if (OldParamHasDfl) {
// ...
} else if (NewParamHasDfl) {
if (New->getDescribedFunctionTemplate()) {
// ...
} else if (New->getTemplateSpecializationKind() != TSK_ImplicitInstantiation && New->getTemplateSpecializationKind() != TSK_Undeclared) {
// ...
Diag(NewParam->getLocation(), diag::err_template_spec_default_arg) << (New->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) << New->getDeclName() << NewParam->getDefaultArgRange();
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/CXX/temp/temp.spec/temp.expl.spec/p21.cpp
- clang/test/CXX/temp/temp.spec/temp.expl.spec/p21.cpp:10:22: error: default argument not permitted on an explicit specialization of function 'mf1'
- clang/test/CXX/temp/temp.spec/temp.expl.spec/p21.cpp:15:27: error: default argument not permitted on an explicit specialization of function 'mf2'