possible clang bug?

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

This looks like a bug for sure, it reproduces on ToT clang for me as well.

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 https://llvm.org/bugs/show_bug.cgi?id=31607
since I didn't find any duplicates.

Alex