Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC template deduction removes const bug?

Tags:

c++

gcc

templates

I found this snippet compiles and runs with GCC7.3 but not with clang7:

const std::vector foo({1, 2, 3, 4});
foo.clear();

I expect a compiler error but GCC happily clears the vector.

like image 542
user3165937 Avatar asked Feb 07 '19 11:02

user3165937


1 Answers

This is GCC bug 83818; it is fixed with GCC 8.

There is unfortunately not much more information there – the only "fix" appears to be not using class template argument deduction or upgrading the compiler.

like image 50
hlt Avatar answered Nov 04 '22 12:11

hlt