Clang Crash despite correctly diagnosing errors

Hello,

I was playing around with clang on a pet project where I rewrote a sibling to StringRef (really love this class).

It turns out I made a couple of errors, but clang still crashes badly (unfortunately no memory dump, didn’t managed to find out if it is at all possible on mingw/msys).

Without further ado, here is the file:

#include

class StringRef
{
public:
typedef std::size_t Length;

StringRef(std::string const& s): buffer(s.buffer()), length(s.size() {}

template
StringRef(char const (&s)[N]): buffer(s), length(N-1) {}

private:
char const* buffer;
Length length;
}; // class StringRef

And here is Clang output:

$ clang++ -fsyntax-only -std=c++0x crasher.cpp -v
clang version 3.0 (trunk 132889)
Target: i686-pc-mingw32
Thread model: posix
“d:/clang/build-cmake/bin/clang++.exe” -cc1 -triple i686-pc-mingw32 -fsyntax-only -disable-free -main-file-name crasher.cpp -mrelocation-model static -mdisable-fp-elim -mconstructor-aliases -target-cpu pentium4 -momit-leaf-frame-pointer -v -resource-dir d:/clang/build-cmake/bin..\lib\clang\3.0 -fdeprecated-macro -ferror-limit 19 -fmessage-length 200 -fobjc-infer-related-result-type -fcxx-exceptions -fexceptions -fno-use-cxa-atexit -fgnu-runtime -fdiagnostics-show-option -fcolor-diagnostics -x c++ …/test/crasher.cpp
clang -cc1 version 3.0 based upon llvm 3.0 hosted on i686-pc-mingw32
ignoring nonexistent directory “c:/MinGW/lib/gcc/mingw32/4.5.0/include/c++”
ignoring nonexistent directory “c:/MinGW/lib/gcc/mingw32/4.5.0/include/c++/mingw32”
ignoring nonexistent directory “c:/MinGW/lib/gcc/mingw32/4.5.0/include/c++/backward”
ignoring nonexistent directory “c:/MinGW/lib/gcc/mingw32/4.4.0/include/c++”
ignoring nonexistent directory “c:/MinGW/lib/gcc/mingw32/4.4.0/include/c++/mingw32”
ignoring nonexistent directory “c:/MinGW/lib/gcc/mingw32/4.4.0/include/c++/backward”
ignoring nonexistent directory “c:/MinGW/lib/gcc/mingw32/4.3.0/include/c++”
ignoring nonexistent directory “c:/MinGW/lib/gcc/mingw32/4.3.0/include/c++/mingw32”
ignoring nonexistent directory “c:/MinGW/lib/gcc/mingw32/4.3.0/include/c++/backward”
ignoring nonexistent directory “/usr/local/include”
ignoring nonexistent directory “c:/mingw/include”
ignoring nonexistent directory “/usr/include”
#include “…” search starts here:
#include <…> search starts here:
/mingw/lib/gcc/mingw32/4.5.2/include/c++
/mingw/lib/gcc/mingw32/4.5.2/include/c++/mingw32
/mingw/lib/gcc/mingw32/4.5.2/include/c++/backward
d:/clang/build-cmake/bin/…/lib/clang/3.0/include
/mingw/include
End of search list.
…/test/crasher.cpp:16:22: error: expected ‘}’
}; // class StringRef
^
…/test/crasher.cpp:4:1: note: to match this ‘{’
{
^
…/test/crasher.cpp:8:45: error: no member named ‘buffer’ in ‘std::basic_string’
StringRef(std::string const& s): buffer(s.buffer()), length(s.size() {}
~ ^
…/test/crasher.cpp:8:72: error: expected ‘)’
StringRef(std::string const& s): buffer(s.buffer()), length(s.size() {}
^
…/test/crasher.cpp:8:62: note: to match this ‘(’
StringRef(std::string const& s): buffer(s.buffer()), length(s.size() {}
^
…/test/crasher.cpp:8:56: error: member initializer ‘length’ does not name a non-static data member or base class
StringRef(std::string const& s): buffer(s.buffer()), length(s.size() {}
^~~~~~~~~~~~~~~~~
…/test/crasher.cpp:14:21: error: expected ‘{’ or ‘,’
char const* buffer;
^
…/test/crasher.cpp:15:3: error: unknown type name ‘Length’
Length length;
^
Stack dump:
0. Program arguments: d:/clang/build-cmake/bin/clang++.exe -cc1 -triple i686-pc-mingw32 -fsyntax-only -disable-free -main-file-name crasher.cpp -mrelocation-model static -mdisable-fp-elim -mconstructor-aliases -target-cpu pentium4 -momit-leaf-frame-pointer -v -resource-dir d:/clang/build-cmake/bin..\lib\clang\3.0 -fdeprecated-macro -ferror-limit 19 -fmessage-length 200 -fobjc-infer-related-result-type -fcxx-exceptions -fexceptions -fno-use-cxa-atexit -fgnu-runtime -fdiagnostics-show-option -fcolor-diagnostics -x c++ …/test/crasher.cpp

  1. …/test/crasher.cpp:15:10: current parser token ‘length’
    01438F96 (0xB381E376 0x0000003C 0x0000000E 0x01355CB1)
    0048A83E (0x024A9900 0x022F9370 0x0022E268 0x0022E28C)
    01355EF3 (0x0225A4C0 0x022F9370 0x7C920041 0x003E0C28)
    0048B440 (0x0225A4C0 0x00000001 0x0022E2C8 0x014505D5)
    01355FF4 (0x0225A4C0 0x00000000 0x00000007 0x0022E2E8)
    013928DC (0x02284FC8 0x00000006 0x0000011A 0x00000268)
    004D25EE (0x02284FC8 0x0022E6C4 0x00000000 0x00000001)
    004B3F81 (0x02284FC8 0x0022E898 0x004B4714 0x00000000)
    004B3E8A (0x02284FC8 0x0022E898 0x0022ED14 0x00000000)
    004AD6BB (0x02284FC8 0x0022ED14 0x00000000 0x00000001)
    0049F57C (0x02284FC8 0x0022ED14 0x00000003 0x00000000)
    0049F5D2 (0x02284FC8 0x0022F118 0x00000003 0x0022F038)
    0049EF2B (0x02284FC8 0x0022F118 0x00000000 0x0022F11C)
    0049E5DB (0x02284FC8 0x0022F160 0x022841C8 0x00456349)
    0049C313 (0x022841C8 0x00000000 0x00000000 0x0143DE78)
    00460D24 (0x0225AC30 0x0225A1DC 0x00000013 0xFFFFFFFF)
    004609AE (0x0225AC30 0x003EFEA8 0x0225AB84 0x00000013)
    004572F5 (0x003EFEA8 0x0225AC30 0x00000003 0x00000000)
    0047904B (0x003EFEA8 0x0225A8F0 0x0022F6F0 0x00000000)
    004038F5 (0x0022F6F0 0x0022F76C 0x003EFEF4 0x004013C0)
    00402739 (0x7FFDF000 0x000001E7 0x0022FFA0 0x004010DB)
    004010DB (0x00000001 0xB5B04D08 0x7C91DCBA 0x7C817074)
    00401178 (0x000001A6 0x000001E7 0x7FFDF000 0xC0000005)
    7C817077 (0x00401160 0x00000000 0x78746341 0x00000020), RegisterWaitForInputIdle()+0073 bytes(s)
    clang++: error: clang frontend command failed due to signal 1073741819 (use -v to see invocation)

I didn’t succeeded in reducing the file further, so it seems a gross combination is necessary…

Removing the call to s.buffer() (non-existing function) make the error go away
Closing the parenthesis after length(s.size() make the error go away
Removing the template constructor make the error go away

Does it ring a bell ?

– Matthieu.

Please just file a Bugzilla. Unless there is some interesting architectural or significant language-interpretation problem involved in the bug, there's not reason to discuss it here.

  - Doug