diff options
| author | Eric Fiselier <eric@efcs.ca> | 2019-02-01 22:06:02 +0000 |
|---|---|---|
| committer | Eric Fiselier <eric@efcs.ca> | 2019-02-01 22:06:02 +0000 |
| commit | 1147f71fed863639e3695a8be6979c39397d88b6 (patch) | |
| tree | fa7d7f4ad57310891cadad2ea809660f0623975c /clang | |
| parent | 2e719bc428d27345da7cdcfa634c03ec69f31474 (diff) | |
| download | bcm5719-llvm-1147f71fed863639e3695a8be6979c39397d88b6.tar.gz bcm5719-llvm-1147f71fed863639e3695a8be6979c39397d88b6.zip | |
Improve diagnostic to tell you a type is incomplete.
I recently ran into this code:
```
\#include <iostream>
void foo(const std::string &s, const std::string& = "");
\#include <string>
void test() { foo(""); }
```
The diagnostic produced said it can't bind char[1] to std::string
const&. It didn't mention std::string is incomplete. The user had to
infer that.
This patch causes the diagnostic to now say "incomplete type".
llvm-svn: 352927
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 5 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 1 | ||||
| -rw-r--r-- | clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp | 2 | ||||
| -rw-r--r-- | clang/test/SemaCXX/decl-init-ref.cpp | 9 |
4 files changed, 14 insertions, 3 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 4271833beca..cf4b71a2afb 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -1828,8 +1828,9 @@ def err_reference_bind_drops_quals : Error< "'volatile'|'const' and 'volatile'|'restrict' and 'volatile'|" "'const', 'restrict', and 'volatile'}2 qualifier%plural{1:|2:|4:|:s}2">; def err_reference_bind_failed : Error< - "reference %diff{to type $ could not bind to an %select{rvalue|lvalue}1 of " - "type $|could not bind to %select{rvalue|lvalue}1 of incompatible type}0,2">; + "reference %diff{to %select{type|incomplete type}1 $ could not bind to an " + "%select{rvalue|lvalue}2 of type $|could not bind to %select{rvalue|lvalue}2 of " + "incompatible type}0,3">; def err_reference_bind_init_list : Error< "reference to type %0 cannot bind to an initializer list">; def err_init_list_bad_dest_type : Error< diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index c1a7d479974..6b9270a9e47 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -8450,6 +8450,7 @@ bool InitializationSequence::Diagnose(Sema &S, case FK_ReferenceInitFailed: S.Diag(Kind.getLocation(), diag::err_reference_bind_failed) << DestType.getNonReferenceType() + << DestType.getNonReferenceType()->isIncompleteType() << OnlyArg->isLValue() << OnlyArg->getType() << Args[0]->getSourceRange(); diff --git a/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp b/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp index f371891e548..9a82ec4a7bd 100644 --- a/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp +++ b/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp @@ -327,7 +327,7 @@ namespace update_rbrace_loc_crash { struct A {}; template <typename T, typename F, int... I> std::initializer_list<T> ExplodeImpl(F p1, A<int, I...>) { - // expected-error@+1 {{reference to type 'const update_rbrace_loc_crash::Incomplete' could not bind to an rvalue of type 'void'}} + // expected-error@+1 {{reference to incomplete type 'const update_rbrace_loc_crash::Incomplete' could not bind to an rvalue of type 'void'}} return {p1(I)...}; } template <typename T, int N, typename F> diff --git a/clang/test/SemaCXX/decl-init-ref.cpp b/clang/test/SemaCXX/decl-init-ref.cpp index 42b9286852c..fb5ca8c1491 100644 --- a/clang/test/SemaCXX/decl-init-ref.cpp +++ b/clang/test/SemaCXX/decl-init-ref.cpp @@ -36,3 +36,12 @@ namespace PR16502 { int f(); const A &c = { 10, ++c.temporary }; } + +namespace IncompleteTest { + struct String; + // expected-error@+1 {{reference to incomplete type 'const IncompleteTest::String' could not bind to an lvalue of type 'const char [1]'}} + void takeString(const String& = "") {} // expected-note {{passing argument to parameter here}} expected-note {{candidate function}} + void test() { + takeString(); // expected-error {{no matching function for call}} + } +} |

