This compiles in clang 3.8 but I believe it should not:
template< class T = int >
struct A
{
struct B {};
const B* test (const B* b) const;
};
template< class T >
inline auto A< T >::test (const B* const b) const → const B*
{
return ++b;
}
int main()
{
A<> m;
const A<>::B* b = 0;
b = m.test (b);
}
Here is the same code in coliru:
http://coliru.stacked-crooked.com/a/55a3a6e7d28e8a5d
gcc reports the error I was expecting:
main.cpp: In instantiation of ‘const A::B* A::test(const A::B*) const [with T = int]’:
main.cpp:19:18: required from here
main.cpp:12:9: error: increment of read-only parameter ‘b’
return ++b;
This is a very non-critical bug (if it even is a bug) and I do not need a fix but I thought I would point it out because I happened to notice.
Thanks,
Adam Burr
Blue Sky Studios
hyp
January 9, 2017, 3:13pm
2
This looks like a bug for sure, it reproduces on ToT clang for me as well.
hyp
January 11, 2017, 2:15pm
3
This compiles in clang 3.8 but I believe it should not:
template< class T = int >
struct A
{
struct B {};
const B* test (const B* b) const;
};
template< class T >
inline auto A< T >::test (const B* const b) const -> const B*
{
return ++b;
}
int main()
{
A<> m;
const A<>::B* b = 0;
b = m.test (b);
}
Here is the same code in coliru:
Coliru Viewer
gcc reports the error I was expecting:
main.cpp: In instantiation of 'const A<T>::B* A<T>::test(const A<T>::B*)
const [with T = int]':
main.cpp:19:18: required from here
main.cpp:12:9: error: increment of read-only parameter 'b'
return ++b;
This is a very non-critical bug (if it even is a bug) and I do not need a
fix but I thought I would point it out because I happened to notice.
Thanks for reporting this issue!
I've created a bugzilla entry at 31607 – Clang accepts invalid code that mutates a const parameter when it is defined with a 'const' qualifier but declared without the 'const' in a class template
since I didn't find any duplicates.
Alex