llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.66k stars 11.85k forks source link

Misleading error message "unions cannot have base classes" #45785

Open haoxintu opened 4 years ago

haoxintu commented 4 years ago
Bugzilla Link 46440
Version trunk
OS Linux
CC @zygoloid

Extended Description

$cat bug.cc class A1 {}; class A2 {}; class A3 {}; union : A1, A2, A3 {} u;

$clang++ -c bug.cc bug.cc:4:1: error: unions cannot have base classes union : A1, A2, A3 {} u; ^ ~~ bug.cc:4:1: error: unions cannot have base classes union : A1, A2, A3 {} u; ^ ~~ bug.cc:4:1: error: unions cannot have base classes union : A1, A2, A3 {} u; ^ ~~ 3 errors generated.

In GCC $g++ -c bug.cc bug.cc:4:17: error: derived union ‘’ invalid 4 | union : A1, A2, A3 {} u; | ^~

I doubt that how clang deal with this case. I guess there are two situations:

  1. Clang gives the wrong column number
  2. Clang duplicates the error message

According to the marking "~~" in error messages, I guess clang might have the first issue?

Also, I have tested it in almost all clang versions, they all have this issue.

ec04fc15-fa35-46f2-80e1-5d271f2ef708 commented 4 years ago

We could diagnose this better; it'd be preferable to produce a single diagnostic perhaps pointing to the : token and underlining both the union and the base-specifiers.

(But this isn't a bug, per se.)