Hi, g++ asked me to submit a bug report, so here it is :) === ERROR === main.cpp:37:69: internal compiler error: unexpected expression ‘static_cast<int>(std::is_same<T, A1>{})’ of kind static_cast_expr static constexpr int value = static_cast<int>(std::is_same<T, A1>{}); ^ Please submit a full bug report, with preprocessed source if appropriate. See <http://gcc.gnu.org/bugs.html> for instructions. === SOURCE === #include <type_traits> template<typename T, typename A1, typename... Args> struct CountType { static constexpr int value = CountType<T, A1>::value + CountType<T, Args...>::value; constexpr operator int() const { return value; } }; template<typename T, typename A1> struct CountType<T, A1> { // static constexpr int value = static_cast<int>(std::is_same<T, A1>()); // this works static constexpr int value = static_cast<int>(std::is_same<T, A1>{}); constexpr operator int() const { return value; } }; template<typename T, typename... Args> using CountDecayType = CountType<T, std::decay_t<Args>...>; template<typename... Args> void foo(Args&&... args) { int i = CountDecayType<int, Args...>{}; } int main() { foo(5, 6L, 5, 5); return 0; } === g++ flags === -std=c++14 -pedantic-errors -Wall -Wextra -gdwarf-2 === configure === Using built-in specs. COLLECT_GCC=/opt/szn/bin/g++-4.9 COLLECT_LTO_WRAPPER=/opt/szn/lib/gcc/x86_64-linux-gnu/4.9.1/lto-wrapper Target: x86_64-linux-gnu Configured with: /home/tomas/packages/gcc/gcc-4.9.1/configure --prefix=/opt/szn --program-suffix=-4.9 --enable-languages=c++ --disable-multilib --enable-shared --enable-threads=posix --enable-checking=release --enable-__cxa_atexit --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-plugin --with-tune=generic --enable-libstdcxx-time=yes --enable-libstdcxx-debug --enable-version-specific-runtime-libs --enable-objc-gc --enable-clocale=gnu --disable-install-libiberty --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --libdir=/opt/szn/lib --libexecdir=/opt/szn/lib --infodir=/opt/szn/share/info-gcc-4.9 --localedir=/opt/szn/share/locale-gcc-4.9 --mandir=/opt/szn/share/man-gcc-4.9 --with-gxx-include-dir=/opt/szn/include/c++/4.9 Thread model: posix gcc version 4.9.1 (GCC)
markus@x4 tmp % cat booo.ii template <typename T> struct A { static constexpr int value = int(T{}); }; markus@x4 tmp % g++ -std=c++11 booo.ii booo.ii:3:39: internal compiler error: unexpected expression ‘(int)(T{})’ of kind cast_expr static constexpr int value = int(T{}); ^ 0x713c8e cxx_eval_constant_expression ../../gcc/gcc/cp/semantics.c:9990 0x716b15 cxx_eval_outermost_constant_expr ../../gcc/gcc/cp/semantics.c:10010 0x624e74 store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, int) ../../gcc/gcc/cp/typeck2.c:810 0x5971d4 check_initializer ../../gcc/gcc/cp/decl.c:5877 0x5a852f cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int) ../../gcc/gcc/cp/decl.c:6399 0x65c1b6 grokfield(cp_declarator const*, cp_decl_specifier_seq*, tree_node*, bool, tree_node*, tree_node*) ../../gcc/gcc/cp/decl2.c:1020 0x69e5e9 cp_parser_member_declaration ../../gcc/gcc/cp/parser.c:20881 0x67a2dc cp_parser_member_specification_opt ../../gcc/gcc/cp/parser.c:20429 0x67a2dc cp_parser_class_specifier_1 ../../gcc/gcc/cp/parser.c:19619 0x67ccb0 cp_parser_class_specifier ../../gcc/gcc/cp/parser.c:19855 0x67ccb0 cp_parser_type_specifier ../../gcc/gcc/cp/parser.c:14531 0x697c60 cp_parser_decl_specifier_seq ../../gcc/gcc/cp/parser.c:11772 0x69cd13 cp_parser_single_declaration ../../gcc/gcc/cp/parser.c:23504 0x69d1f4 cp_parser_template_declaration_after_export ../../gcc/gcc/cp/parser.c:23373 0x6a9919 cp_parser_declaration ../../gcc/gcc/cp/parser.c:11172 0x6a83d8 cp_parser_declaration_seq_opt ../../gcc/gcc/cp/parser.c:11094 0x6a9cc3 cp_parser_translation_unit ../../gcc/gcc/cp/parser.c:4059 0x6a9cc3 c_parse_file() ../../gcc/gcc/cp/parser.c:32089 0x7d11e2 c_common_parse_file() ../../gcc/gcc/c-family/c-opts.c:1043 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <http://gcc.gnu.org/bugs.html> for instructions.
We (incorrectly) rejected the code with an error before 4.9.0, now we get an ICE, so marking as a regression.
The error turned into ICE with r196724.
Author: jason Date: Thu Oct 9 18:05:23 2014 New Revision: 216043 URL: https://gcc.gnu.org/viewcvs?rev=216043&root=gcc&view=rev Log: PR c++/63415 * pt.c (value_dependent_expression_p) [CONSTRUCTOR]: Check the type. (iterative_hash_template_arg): Likewise. Added: trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist8.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/pt.c
Author: jason Date: Fri Oct 10 20:35:26 2014 New Revision: 216107 URL: https://gcc.gnu.org/viewcvs?rev=216107&root=gcc&view=rev Log: PR c++/63415 * pt.c (value_dependent_expression_p) [CONSTRUCTOR]: Check the type. (iterative_hash_template_arg): Likewise. Added: branches/gcc-4_9-branch/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist8.C Modified: branches/gcc-4_9-branch/gcc/cp/ChangeLog branches/gcc-4_9-branch/gcc/cp/pt.c
Fixed.
Author: jason Date: Wed Oct 15 16:46:29 2014 New Revision: 216276 URL: https://gcc.gnu.org/viewcvs?rev=216276&root=gcc&view=rev Log: PR c++/63415 * pt.c (value_dependent_expression_p) [CONSTRUCTOR]: Check the type. (iterative_hash_template_arg): Likewise. Added: branches/gcc-4_8-branch/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist8.C Modified: branches/gcc-4_8-branch/gcc/cp/ChangeLog branches/gcc-4_8-branch/gcc/cp/pt.c
Fixing the error in 4.8 as well.