Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: A possibly ill-formed program

21 views
Skip to first unread message

Paavo Helde

unread,
Dec 6, 2016, 2:03:39 PM12/6/16
to
On 6.12.2016 20:00, Stefan Ram wrote:
> I got this diagnostics
>
> main.cpp:9:29: error: integer constant is too large for its type
> int main() { ::std::cout << 340282366920938463463374607431768211456 << "\n"s; }
> ^
> C++ says:
>
> A program is ill-formed if one of its translation units contains an
> integer literal that cannot be represented by any of the allowed types.
>
> A web compiler printed »0« for the above program recently IIRC.
>
> Is an implementation required to print a diagnostic message
> for an ill-formed program¹, and - when being executed - does
> an ill-formed program have undefined behavior?
>
> (¹If so, then that web compiler might not be conforming.)
>
> But since there might be an implementation with a very large
> integral type, the above program might not be ill-formed
> under such an implementation, so whether a program is
> ill-formed depends on the implementation used?

From the standard:

"A conforming implementation may have extensions (including additional
library functions), provided they do not alter the behavior of any
well-formed program. Implementations are required to diagnose programs
that use such extensions that are ill-formed according to this
International Standard. Having done so, however, they can compile and
execute such programs."

So, as long as the web compiler produced some warning message about the
too large number, it behaved correctly. For example, gcc 5.3.0 produces
a warning:

tmp>g++ test22.cpp
test22.cpp:3:29: warning: integer constant is too large for its type
int main() { ::std::cout << 340282366920938463463374607431768211456 <<
"\n"; }
Lap: tmp>./a.exe
0


0 new messages