This fixes PR23931 .
I'm not entirely sure about the words of the error message.
Details
Diff Detail
Event Timeline
Example after patching:
$ clang++ union.cpp -o union
union.cpp:2:3: error: function 'f' declared 'virtual' within a union
virtual void f(...); ^
1 error generated.
g++ output, for reference
$ g++5 union.cpp -o union
union.cpp:2:21: error: function 'f' declared virtual inside a union
virtual void f(...); ^
LGTM with minor tweaks.
include/clang/Basic/DiagnosticSemaKinds.td | ||
---|---|---|
1266 | This diagnostic is true, but doesn't actually explain what the problem is to someone unaware of the language rule. Also, listing the function name doesn't seem useful as the diagnostic is pointing at the function. Would just "unions cannot have virtual functions" work for you? | |
lib/Sema/SemaDecl.cpp | ||
7211 | Do we need to mark the function as invalid? It seems like we should be able to recover from this case fine, without any follow-on problems. (In fact, it's a little disturbing how /well/ we support unions with virtual functions today...) |
This diagnostic is true, but doesn't actually explain what the problem is to someone unaware of the language rule. Also, listing the function name doesn't seem useful as the diagnostic is pointing at the function. Would just "unions cannot have virtual functions" work for you?