使用遞迴模板理論上可以造出無限多個錯誤。
// https://gcc.godbolt.org/z/97v858
template <int N>
struct Fuck {
int arr[-N];
Fuck<N + 1> next;
};
Fuck<1> f;
<source>: In instantiation of "struct Fuck<1>":
<source>:8:9: required from here
<source>:3:9: error: narrowing conversion of "-1" from "int" to "long unsigned int" [-Wnarrowing]
3 | int arr[-N];
| ^~~
<source>:3:9: error: size "-1" of array is negative
<source>: In instantiation of "struct Fuck<2>":
<source>:4:17: required from "struct Fuck<1>"
<source>:3:9: error: narrowing conversion of "-2" from "int" to "long unsigned int" [-Wnarrowing]
<source>:3:9: error: size "-2" of array is negative
<source>: In instantiation of "struct Fuck<3>":
<source>:4:17: recursively required from "struct Fuck<2>"
<source>:3:9: error: narrowing conversion of "-3" from "int" to "long unsigned int" [-Wnarrowing]
<source>:3:9: error: size "-3" of array is negative
<source>: In instantiation of "struct Fuck<4>":
<source>:3:9: error: narrowing conversion of "-4" from "int" to "long unsigned int" [-Wnarrowing]
<source>:3:9: error: size "-4" of array is negative
<source>: In instantiation of "struct Fuck<5>":
<source>:3:9: error: narrowing conversion of "-5" from "int" to "long unsigned int" [-Wnarrowing]
<source>:3:9: error: size "-5" of array is negative
<source>: In instantiation of "struct Fuck<6>":
<source>:3:9: error: narrowing conversion of "-6" from "int" to "long unsigned int" [-Wnarrowing]
<source>:3:9: error: size "-6" of array is negative
<source>: In instantiation of "struct Fuck<7>":
<source>:3:9: error: narrowing conversion of "-7" from "int" to "long unsigned int" [-Wnarrowing]
<source>:3:9: error: size "-7" of array is negative
<source>: In instantiation of "struct Fuck<8>":
<source>:3:9: error: narrowing conversion of "-8" from "int" to "long unsigned int" [-Wnarrowing]
<source>:3:9: error: size "-8" of array is negative
<source>: In instantiation of "struct Fuck<9>":
<source>:3:9: error: narrowing conversion of "-9" from "int" to "long unsigned int" [-Wnarrowing]
<source>:3:9: error: size "-9" of array is negative
<source>: In instantiation of "struct Fuck<10>":
<source>:3:9: error: narrowing conversion of "-10" from "int" to "long unsigned int" [-Wnarrowing]
<source>:3:9: error: size "-10" of array is negative
……
使用遞迴模板理論上可以造出無限多個錯誤。
// https://gcc.godbolt.org/z/97v858
template <int N>
struct Fuck {
int arr[-N];
Fuck<N + 1> next;
};
Fuck<1> f;
<source>: In instantiation of "struct Fuck<1>":
<source>:8:9: required from here
<source>:3:9: error: narrowing conversion of "-1" from "int" to "long unsigned int" [-Wnarrowing]
3 | int arr[-N];
| ^~~
<source>:3:9: error: size "-1" of array is negative
<source>: In instantiation of "struct Fuck<2>":
<source>:4:17: required from "struct Fuck<1>"
<source>:8:9: required from here
<source>:3:9: error: narrowing conversion of "-2" from "int" to "long unsigned int" [-Wnarrowing]
<source>:3:9: error: size "-2" of array is negative
<source>: In instantiation of "struct Fuck<3>":
<source>:4:17: recursively required from "struct Fuck<2>"
<source>:4:17: required from "struct Fuck<1>"
<source>:8:9: required from here
<source>:3:9: error: narrowing conversion of "-3" from "int" to "long unsigned int" [-Wnarrowing]
<source>:3:9: error: size "-3" of array is negative
<source>: In instantiation of "struct Fuck<4>":
<source>:4:17: recursively required from "struct Fuck<2>"
<source>:4:17: required from "struct Fuck<1>"
<source>:8:9: required from here
<source>:3:9: error: narrowing conversion of "-4" from "int" to "long unsigned int" [-Wnarrowing]
<source>:3:9: error: size "-4" of array is negative
<source>: In instantiation of "struct Fuck<5>":
<source>:4:17: recursively required from "struct Fuck<2>"
<source>:4:17: required from "struct Fuck<1>"
<source>:8:9: required from here
<source>:3:9: error: narrowing conversion of "-5" from "int" to "long unsigned int" [-Wnarrowing]
<source>:3:9: error: size "-5" of array is negative
<source>: In instantiation of "struct Fuck<6>":
<source>:4:17: recursively required from "struct Fuck<2>"
<source>:4:17: required from "struct Fuck<1>"
<source>:8:9: required from here
<source>:3:9: error: narrowing conversion of "-6" from "int" to "long unsigned int" [-Wnarrowing]
<source>:3:9: error: size "-6" of array is negative
<source>: In instantiation of "struct Fuck<7>":
<source>:4:17: recursively required from "struct Fuck<2>"
<source>:4:17: required from "struct Fuck<1>"
<source>:8:9: required from here
<source>:3:9: error: narrowing conversion of "-7" from "int" to "long unsigned int" [-Wnarrowing]
<source>:3:9: error: size "-7" of array is negative
<source>: In instantiation of "struct Fuck<8>":
<source>:4:17: recursively required from "struct Fuck<2>"
<source>:4:17: required from "struct Fuck<1>"
<source>:8:9: required from here
<source>:3:9: error: narrowing conversion of "-8" from "int" to "long unsigned int" [-Wnarrowing]
<source>:3:9: error: size "-8" of array is negative
<source>: In instantiation of "struct Fuck<9>":
<source>:4:17: recursively required from "struct Fuck<2>"
<source>:4:17: required from "struct Fuck<1>"
<source>:8:9: required from here
<source>:3:9: error: narrowing conversion of "-9" from "int" to "long unsigned int" [-Wnarrowing]
<source>:3:9: error: size "-9" of array is negative
<source>: In instantiation of "struct Fuck<10>":
<source>:4:17: recursively required from "struct Fuck<2>"
<source>:4:17: required from "struct Fuck<1>"
<source>:8:9: required from here
<source>:3:9: error: narrowing conversion of "-10" from "int" to "long unsigned int" [-Wnarrowing]
<source>:3:9: error: size "-10" of array is negative
……