Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instantiation of class template causes instantiation of static data member's definition #81191

Open
BobBugs opened this issue Feb 8, 2024 · 3 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" rejects-valid

Comments

@BobBugs
Copy link

BobBugs commented Feb 8, 2024

According to C++20 [temp.inst]/3.1 the definition of static data member i should not be instantiated, and therefore the program must compile:

template <class T>
class C {
    static const int i = T::value;
};

C<void> x;

Clang 17.0.1 instantiates it, and compilation fails. Demo.

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" rejects-valid and removed new issue labels Feb 8, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 8, 2024

@llvm/issue-subscribers-clang-frontend

Author: None (BobBugs)

According to C++20 [\[temp.inst\]/3.1](https://timsong-cpp.github.io/cppwp/n4868/temp.inst#3.1) the definition of static data member `i` should not be instantiated, and therefore the program must compile:
template &lt;class T&gt;
class C {
    static const int i = T::value;
};

C&lt;void&gt; x;

Clang 17.0.1 instantiates it, and compilation fails. Demo.

@shafik
Copy link
Collaborator

shafik commented Feb 9, 2024

Note only gcc accepts: https://godbolt.org/z/KbY7h37bW

I think this is related to: #59966 (comment)

@zygoloid
Copy link
Collaborator

zygoloid commented Feb 9, 2024

This example contains only a declaration, not a definition, of the static data member. The initializer is part of that declaration, so gets instantiated with the class.

I think clang is correct here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" rejects-valid
Projects
None yet
Development

No branches or pull requests

5 participants