[Bug c++/66923] New: Variable template initialized using auto deduces wrong type
sneves at dei dot uc.pt
gcc-bugzilla@gcc.gnu.org
Sat Jul 18 00:27:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66923
Bug ID: 66923
Summary: Variable template initialized using auto deduces wrong
type
Product: gcc
Version: 5.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: sneves at dei dot uc.pt
Target Milestone: ---
Consider the following sample:
template<int> struct S {};
template<int N>
constexpr auto V = S<N>{};
// constexpr S<N> V{}; // This works
template<typename T>
auto f(T) {
return V<(
#if defined(TRIGGER_ERROR)
(void)T(),
#endif
0)>;
}
int main() {
f(0);
}
If TRIGGER_ERROR is defined, the definition of V is dependent on the deduced
type T. In this case, GCC will seemingly deduce that the type of V<int> is T:
error: cannot convert 'S<0>' to 'const int' in initialization
constexpr auto V = S<N>{};
When V's parameter does not depend on T, the program compiles as expected. This
affects GCC 5.x and 6.x in C++14 mode.
More information about the Gcc-bugs
mailing list