Topic: Attribute-specifier ambiguity with other
Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@gmail.com>
Date: Mon, 11 Feb 2013 22:58:16 +0100
Raw View
2013/2/11 Vlad from Moscow <vlad.moscow@mail.ru>:
> I think that paragraph #6 of section 7.6.1 Attribute syntax and semantics
> shall include a mention about an error message
The standard in general does not require "an error message", it only
talks about well-formed and ill-formed programs. Further-on it says in
[intro.compliance] p2 b2:
"Although this International Standard states only requirements on C++
implementations, those requirements
are often easier to understand if they are phrased as requirements on
programs, parts of programs, or
execution of programs. Such requirements have the following meaning:
[..]
=E2=80=94 If a program contains a violation of any diagnosable rule or an
occurrence of a construct described in
this Standard as =E2=80=9Cconditionally-supported=E2=80=9D when the impleme=
ntation
does not support that construct,
a conforming implementation shall issue at least one diagnostic message.
[..]"
This is all we need to reflect upon your example code:
>> 6 Two consecutive left square bracket tokens shall appear only when
>> introducing an attribute-speci=EF=AC=81er. [ Note:
>> If two consecutive left square brackets appear where an attribute-speci=
=EF=AC=81er
>> is not allowed, the program is ill formed even if the brackets match an
>> alternative grammar production. =E2=80=94 end note ] [Example:
>> int p[10];
>> void f() {
>> int x =3D 42, y[5];
>> int(p[[x] { return x; }()]); // error: malformed attribute on a nested
>> // declarator-id and not a function-style cast of
>> // an element of p.
>> y[[] { return 2; }()] =3D 2; // error even though attributes are not all=
owed
>> // in this context.
>> }
>> =E2=80=94 end example ]
>
>
> I tried the following example
>
>
> #include <iostream>
>
> int main()
> {
> const char *s =3D "Hello";
>
> std::cout << s[[]{ return 1; }()] << std::endl;
>
> return 0;
> }
>
>
> and most compilers compile the code without any warning. I think that it =
is
> not enough simply to say that the program is ill-formed. I think that the
> compiler shall issue an error message because it is very difficult to fin=
d
> such ambiguity with the attribute-specifiers in code.
The rules already require at least one diagnostic message. This is a
general way how the standard is defined and should suffice in this
case.[1] If a compiler does not diagnose this, it has a bug. There is
no need to say anything more.
- Daniel
[1] There exists one special case where the C99 standard imposes
stronger requirements, see
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#745
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/?hl=3Den.
.