[Bug c++/57891] New: No diagnostic of narrowing conversion in non-type template argument
imkinghan at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sat Jul 13 06:51:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57891
Bug ID: 57891
Summary: No diagnostic of narrowing conversion in non-type
template argument
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: imkinghan at gmail dot com
In the following C++11 program:
template<unsigned N>
struct A{};
int main()
{
A<1-2> a;
(void)a;
return 0;
}
the declaration of `a` requires a narrowing conversion to be diagnosed per
C++11 Standard § 14.3.2/5:
>For a non-type template-parameter of integral or enumeration type, conversions
>permitted in a converted constant expression (5.19) are applied.
and § 5.19/3:
>A converted constant expression of type T is a literal constant expression,
>implicitly converted to type T, where the implicit conversion (if any) is
>permitted in a literal constant expression and the implicit conversion sequence
>contains only user-defined conversions, lvalue-to-rvalue conversions (4.1),
>integral promotions (4.5), and integral conversions (4.7) other than narrowing
>conversions (8.5.4)
No diagnostic is forthcoming (-std-c++11;-Wall). The same narrowing conversion,
from -1 to `unsigned`, is diagnosed (with a warning) in other contexts where
the Standard prohibits the narrowing conversion, e.g.
unsigned int ui = { -1 };
A compiler that diagnoses the narrowing conversion of a non-type template
argument (clang 3.2/3.3 makes it an error) will pinpoint a TMP bug in which
an unsigned template argument falls recursively through 0, while g++ will just
exceed `-ftemplate-depth`.
This report stems from my Stackoverflow question
http://stackoverflow.com/q/17559165/1362568
More information about the Gcc-bugs
mailing list