I confused the compiler

Clang is known for its great error messages, but I did manage to horribly confuse it:

#include <cstddef>
 
class Foo
{
public:
  constexpr Foo(nullptr_t) noexcept { }
};
$ clang++ -std=c++11 foo.cpp
foo.cpp:6:3: error: non-static data member cannot be constexpr; did you intend to make it const?
  constexpr Foo(nullptr_t) noexcept { }
  ^~~~~~~~~
  const
foo.cpp:6:17: error: field has incomplete type 'const Foo'
  constexpr Foo(nullptr_t) noexcept { }
                ^
foo.cpp:3:7: note: definition of 'Foo' is not complete until the closing '}'
class Foo
      ^
foo.cpp:6:27: error: expected ';' at end of declaration list
  constexpr Foo(nullptr_t) noexcept { }
                          ^
                          ;
3 errors generated.

Somehow it decided that my constructor is actually a field, then complained loudly of the many ways it's not a valid field declaration.

(The actual error is that I should have written std::nullptr_t.)

Leave a Reply

Your email address will not be published. Required fields are marked *