This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/59960] New: accepts ill-formed 'auto a1 = t1, a2 = t2;' where t1 and t2 have different template types
- From: "gcc at abeckmann dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 27 Jan 2014 17:05:25 +0000
- Subject: [Bug c++/59960] New: accepts ill-formed 'auto a1 = t1, a2 = t2;' where t1 and t2 have different template types
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59960
Bug ID: 59960
Summary: accepts ill-formed 'auto a1 = t1, a2 = t2;' where t1
and t2 have different template types
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: gcc at abeckmann dot de
The following code is accepted by g++ in c++11 mode (tested 4.7, 4.8, 4.9):
===== 8< =====
#include <iostream>
#include <typeinfo>
template <typename T1, typename T2>
void f(T1 & t1, T2 & t2)
{
auto a1 = t1, a2 = t2;
std::cout << typeid(a1).name() << std::endl;
std::cout << typeid(a2).name() << std::endl;
}
int main ()
{
int i(23);
double d(42.);
f(i, d);
}
===== >8 =====
the output id generates is
----- 8< -----
i
d
----- >8 -----
But the standard says in [dcl.spec.auto] clause 7: If the list [...] contains
more than one declarator, the type of each declared variable is determined as
described above. If the type deduced [...] is not the same in each deduction,
the program is ill-formed.
clang fails compilation with
auto2.cpp:7:2: error: 'auto' deduced as 'int' in declaration of 'a1' and
deduced as 'double' in declaration of 'a2'
auto a1 = t1, a2 = t2;
^ ~~ ~~