This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/84196] New: invalid instantiation of a function template on a vector type silently accepted
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 03 Feb 2018 23:28:32 +0000
- Subject: [Bug c++/84196] New: invalid instantiation of a function template on a vector type silently accepted
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84196
Bug ID: 84196
Summary: invalid instantiation of a function template on a
vector type silently accepted
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
GCC rejects invalid calls to ordinary functions that take a vector argument but
it silently accepts and emits bogus code for the invalid code below. Rather
than doing that, it should reject it similarly to how Clang does.
$ cat t.C && gcc -O2 -Wall -Wextra -fdump-tree-optimized=/dev/stdout t.C
template <class T>
int f (T v __attribute__ ((vector_size (16))))
{
return v[0] + v[1] + v[2] + v[3];
}
int main ()
{
return f (12345678);
}
;; Function f<int> (_Z1fIiEiT_, funcdef_no=2, decl_uid=2359, cgraph_uid=1,
symbol_order=1)
f<int> (vector(4) int v)
{
int _1;
int _2;
int _3;
int _4;
int _5;
int _6;
int _8;
<bb 2> [local count: 1073741825]:
_1 = BIT_FIELD_REF <v_9(D), 32, 0>;
_2 = BIT_FIELD_REF <v_9(D), 32, 32>;
_3 = _1 + _2;
_4 = BIT_FIELD_REF <v_9(D), 32, 64>;
_5 = _3 + _4;
_6 = BIT_FIELD_REF <v_9(D), 32, 96>;
_8 = _5 + _6;
return _8;
}
;; Function main (main, funcdef_no=1, decl_uid=2357, cgraph_uid=0,
symbol_order=0) (executed once)
main ()
{
int _2;
<bb 2> [local count: 1073741825]:
_2 = f<int> (12345678); [tail call]
return _2;
}
Clang gives the following error:
t.C:2:28: error: invalid vector element type 'T'
int f (T v __attribute__ ((vector_size (16))))
^
t.C:4:10: error: subscripted value is not an array, pointer, or vector
return v[0] + v[1] + v[2] + v[3];
^ ~
t.C:9:10: note: in instantiation of function template specialization 'f<int>'
requested here
return f (12345678);
^
2 errors generared