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.