llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Clang] Accepts invalid `constexpr` in explicit instantiation of variable template

Open MagentaTreehouse opened this issue 2 years ago • 2 comments

In the following code, the constexpr specifier should not be allowed in the explicit instantiation. It is rejected by GCC, but accepted by Clang.

template <class>
inline constexpr int i{};

template constexpr int i<int>;

See Compiler Explorer: https://godbolt.org/z/jzvY3Mqxc

MagentaTreehouse avatar Oct 02 '24 15:10 MagentaTreehouse

@llvm/issue-subscribers-clang-frontend

Author: None (MagentaTreehouse)

In the following code, the `constexpr` specifier should not be allowed in the explicit instantiation. It is rejected by GCC, but accepted by Clang. ```c++ template <class> inline constexpr int i{};

template constexpr int i<int>;

See Compiler Explorer: https://godbolt.org/z/jzvY3Mqxc
</details>

llvmbot avatar Oct 02 '24 15:10 llvmbot

Interesting edg rejects and MSVC accepts: https://godbolt.org/z/1zWdYzPTv

Using const instead only edg rejects; https://godbolt.org/z/nqM8n8hfK

gcc looks correct based on [temp.explicit]p3: https://eel.is/c++draft/temp.explicit#3:

An explicit instantiation shall not use a storage-class-specifier ([dcl.stc]) other than thread_local. An explicit instantiation of a function template, member function of a class template, or variable template shall not use the inline, constexpr, or consteval specifiers. No attribute-specifier-seq ([dcl.attr.grammar]) shall appertain to an explicit instantiation.

shafik avatar Oct 02 '24 18:10 shafik