Q:

GCC template deduction removes const bug?

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.

A:

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.

