Skip to content

Clang allows template constructor to have different template argument list with that of class definition with default argument #121882

@wangbo15

Description

@wangbo15

The following invalid code is not rejected by clang for incompatible template parameter list between ctor and class definition:

template <class TClass, int NON=0> 
class T 
{ 
public: 
  T<TClass>(int f) {}
}; 

int main(){
    T<int> t(10);
}

EDG and GCC reject it. The diagnostic of GCC is weird though.

EDG rejects it with the following diagnostic, which seems more reasonable.

"<source>", line 5: error: type used as constructor name does not match type "T<TClass, NON>"
    T<TClass>(int f) {}
    ^

1 error detected in the compilation of "<source>".

Please see https://godbolt.org/z/s3KK85qxo

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"diverges-from:edgDoes the clang frontend diverge from edg compiler on this issuediverges-from:gccDoes the clang frontend diverge from gcc on this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions