Interpretation of [dcl.spec.auto]/8

26 views
Skip to first unread message

Anders Granlund

unread,
Jul 26, 2015, 5:17:45 PM7/26/15
to ISO C++ Standard - Discussion
Consider the following program.

auto i = 0, f();
int main() {}

In the c++ standard [decl.spec.auto]/8 (http://eel.is/c++draft/dcl.dcl#dcl.spec.auto-8), says:

"If the init-declarator-list contains more than one init-declarator, they shall all form declarations of variables."

If I understand this correctly, shouldn't the program above be ill-formed?

When compiling it with gcc and clang (using -pedantic-errors and -std=c++14) i get no diagnostic message.


Richard Smith

unread,
Jul 27, 2015, 2:58:12 AM7/27/15
to std-dis...@isocpp.org
Apparently neither of them implement http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1265 yet. 

Anders Granlund

unread,
Jul 27, 2015, 6:36:41 AM7/27/15
to std-dis...@isocpp.org
Ok, so not a bug then. Status CD means that it was added to the current working draft? But I think we can trigger a bug like this:
auto f(), g();
auto f() { return 0; }
auto f() { return 0.0; }
int main() {}
Clang correctly accepts this, but GCC complains in the following way:
prog.cc: In function 'auto g()':
prog.cc:3:19: error: inconsistent deduction for 'auto': 'int' and then 'double'
 auto g() { return 0.0; }
                   ^


--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-discussion/.

Anders Granlund

unread,
Jul 27, 2015, 6:37:45 AM7/27/15
to std-dis...@isocpp.org
Correction: Should be auto g() { return 0.0; } instead of auto f() { return 0.0; } there.

Anders Granlund

unread,
Jul 27, 2015, 7:06:46 AM7/27/15
to std-dis...@isocpp.org
Anyways, doesn't matter. If core defect 1265 is implemented all those resulting problems will disappear anyways. I'll update the bug reports for Clang and GCC with a reference to 1265.
Reply all
Reply to author
Forward
0 new messages