llvm / llvm-project

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

Compiler accepting ill-formed program trying to define a struct via `using-declaration` #24512

Open ebdd6ebc-1612-4e9b-aee1-f7d2b6361d5f opened 9 years ago

ebdd6ebc-1612-4e9b-aee1-f7d2b6361d5f commented 9 years ago
Bugzilla Link 24138
Version trunk
OS All
CC @yeah-boi,@majnemer,@DougGregor,@zygoloid

Extended Description

Consider the following program:

  namespace R {
      struct f;
  }

  namespace S {
      using R::f;
  }
  struct S::f {};

  int main() {}

But clang compiles it without any error messages. The expected behaviour is to get an error message.

The program is ill-formed by the following clauses in the c++ standard:

ebdd6ebc-1612-4e9b-aee1-f7d2b6361d5f commented 9 years ago

This should also be ill-formed, but clang accepts it too (it an even simpler test-case):

  struct S;
  namespace N { using ::S; }
  struct N::S {};
ebdd6ebc-1612-4e9b-aee1-f7d2b6361d5f commented 9 years ago

Disregard the previous comment. It was indented for the same bug in GCC.

ebdd6ebc-1612-4e9b-aee1-f7d2b6361d5f commented 9 years ago

This bug seems to be more general than struct definitions. It also exists for variable declarations like this:

  namespace X { extern int i; }

  namespace N { using X::i; }

  int N::i = 1;

  int main() {}

The above program is ill-formed by [dcl.meaning]p1, but no error message is given.