]> granicus.if.org Git - clang/commit
Reimplement reference initialization (C++ [dcl.init.ref]) using the
authorDouglas Gregor <dgregor@apple.com>
Wed, 9 Dec 2009 23:02:17 +0000 (23:02 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 9 Dec 2009 23:02:17 +0000 (23:02 +0000)
commit20093b4bf698f292c664676987541d5103b65b15
treebd33e2e54c5a41beaea36e5d6fd4a8872e67953c
parent9b39c51ae3c547568ac42325f94b4197618f6b18
Reimplement reference initialization (C++ [dcl.init.ref]) using the
new notion of an "initialization sequence", which encapsulates the
computation of the initialization sequence along with diagnostic
information and the capability to turn the computed sequence into an
expression. At present, I've only switched one CheckReferenceInit
callers over to this new mechanism; more will follow.

Aside from (hopefully) being much more true to the standard, the
diagnostics provided by this reference-initialization code are a bit
better than before. Some examples:

p5-var.cpp:54:12: error: non-const lvalue reference to type 'struct
Derived'
      cannot bind to a value of unrelated type 'struct Base'
  Derived &dr2 = b; // expected-error{{non-const lvalue reference to
  ...
           ^     ~
p5-var.cpp:55:9: error: binding of reference to type 'struct Base' to
a value of
      type 'struct Base const' drops qualifiers
  Base &br3 = bc; // expected-error{{drops qualifiers}}
        ^     ~~

p5-var.cpp:57:15: error: ambiguous conversion from derived class
      'struct Diamond' to base class 'struct Base':
    struct Diamond -> struct Derived -> struct Base
    struct Diamond -> struct Derived2 -> struct Base
  Base &br5 = diamond; // expected-error{{ambiguous conversion from
      ...
              ^~~~~~~
p5-var.cpp:59:9: error: non-const lvalue reference to type 'long'
      cannot bind to
      a value of unrelated type 'int'
  long &lr = i; // expected-error{{non-const lvalue reference to type
      ...
        ^    ~

p5-var.cpp:74:9: error: non-const lvalue reference to type 'struct
Base' cannot
      bind to a temporary of type 'struct Base'
  Base &br1 = Base(); // expected-error{{non-const lvalue reference to
  ...
        ^     ~~~~~~

p5-var.cpp:102:9: error: non-const reference cannot bind to bit-field
'i'
  int & ir1 = (ib.i); // expected-error{{non-const reference cannot
  ...
        ^     ~~~~~~
p5-var.cpp:98:7: note: bit-field is declared here
  int i : 17; // expected-note{{bit-field is declared here}}
      ^

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90992 91177308-0d34-0410-b5e6-96231b3b80d8
25 files changed:
include/clang/AST/DeclCXX.h
include/clang/AST/Type.h
include/clang/Basic/DiagnosticSemaKinds.td
lib/AST/Type.cpp
lib/Sema/Sema.h
lib/Sema/SemaCXXCast.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclCXX.cpp
lib/Sema/SemaExprCXX.cpp
lib/Sema/SemaInit.cpp
lib/Sema/SemaInit.h
lib/Sema/SemaOverload.cpp
lib/Sema/SemaOverload.h
test/CXX/dcl.decl/dcl.init/dcl.init.ref/p1.cpp [new file with mode: 0644]
test/CXX/dcl.decl/dcl.init/dcl.init.ref/p3.cpp [new file with mode: 0644]
test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-examples.cpp [new file with mode: 0644]
test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-var.cpp [new file with mode: 0644]
test/CodeGenCXX/references.cpp
test/SemaCXX/convert-to-bool.cpp
test/SemaCXX/decl-init-ref.cpp
test/SemaCXX/overloaded-operator.cpp
test/SemaCXX/ref-init-ambiguous.cpp
test/SemaCXX/references.cpp
test/SemaCXX/rval-references.cpp
test/SemaTemplate/instantiate-expr-4.cpp