Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

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

Open Quuxplusone opened 9 years ago

Quuxplusone commented 9 years ago
Bugzilla Link PR24138
Status NEW
Importance P normal
Reported by Anders Granlund (anders.granlund.0@gmail.com)
Reported on 2015-07-15 16:19:16 -0700
Last modified on 2015-07-22 16:10:45 -0700
Version trunk
Hardware All All
CC anders.granlund.0@gmail.com, david.majnemer@gmail.com, dgregor@apple.com, ditaliano@apple.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
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:

* [class]p11 ( http://eel.is/c++draft/class#11 ):
Note especially the sentence "i.e., not merely inherited or introduced by a
using-declaration"

* [dcl.meaning]p1 ( http://eel.is/c++draft/dcl.meaning#1 ):
Not especially the sentence "the member shall not merely have been introduced
by a using-declaration in the scope of the class or namespace nominated by the
nested-name-specifier of the declarator-id."
Quuxplusone 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.
Quuxplusone commented 9 years ago

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

Quuxplusone 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 {};