[PATCH] D79160: [AST] Preserve the type in RecoveryExprs for broken function calls.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 30 03:01:46 PDT 2020


hokein added inline comments.


================
Comment at: clang/lib/Sema/SemaOverload.cpp:12779
 
+// Guess at what the return type for an unresolvable overload should be.
+static QualType chooseRecoveryType(OverloadCandidateSet &CS,
----------------
I steal this function from D61722.


================
Comment at: clang/test/SemaCXX/enable_if.cpp:417
 
-constexpr int B = 10 + // the carat for the error should be pointing to the problematic call (on the next line), not here.
-    callTemplated<0>(); // expected-error{{initialized by a constant expression}} expected-error at -3{{no matching function for call to 'templated'}} expected-note{{in instantiation of function template}} expected-note at -10{{candidate disabled}}
+constexpr int B = 10 + // expected-error {{initialized by a constant expression}}
+    callTemplated<0>(); // expected-error at -3{{no matching function for call to 'templated'}} expected-note{{in instantiation of function template}} expected-note at -10{{candidate disabled}} expected-note {{in call to 'callTemplated()'}} expected-note at -3 {{subexpression not valid in a constant expression}}
----------------
this diagnostic is changed slightly (without `-frecovery-ast-type`). I think this is acceptable.

before this patch:

```
/tmp/t5.cpp:7:10: error: no matching function for call to 'templated'
  return templated<N>();  // expected-error {{no matching function for call to 'templated'}} 
         ^~~~~~~~~~~~
/tmp/t5.cpp:13:5: note: in instantiation of function template specialization 'enable_if_diags::callTemplated<0>' requested here
    callTemplated<0>(); // expected-note {{in call to 'callTemplated()'}} expected-note at -6 {{subexpression not valid in a constant expression}}
    ^
/tmp/t5.cpp:2:32: note: candidate disabled: <no message provided>
template <int N> constexpr int templated() __attribute__((enable_if(N, ""))) {
                               ^                                    ~
/tmp/t5.cpp:13:5: error: constexpr variable 'B' must be initialized by a constant expression
    callTemplated<0>(); // expected-note {{in call to 'callTemplated()'}} expected-note at -6 {{subexpression not valid in a constant expression}}
    ^~~~~~~~~~~~~~~~~~
2 errors generated.
```

vs after this patch:

```
/tmp/t5.cpp:7:10: error: no matching function for call to 'templated'
  return templated<N>();  // expected-error {{no matching function for call to 'templated'}} 
         ^~~~~~~~~~~~
/tmp/t5.cpp:13:5: note: in instantiation of function template specialization 'enable_if_diags::callTemplated<0>' requested here
    callTemplated<0>(); // expected-note {{in call to 'callTemplated()'}} expected-note at -6 {{subexpression not valid in a constant expression}}
    ^
/tmp/t5.cpp:2:32: note: candidate disabled: <no message provided>
template <int N> constexpr int templated() __attribute__((enable_if(N, ""))) {
                               ^                                    ~
/tmp/t5.cpp:12:15: error: constexpr variable 'B' must be initialized by a constant expression
constexpr int B = 10 +  // expected-error {{constexpr variable 'B' must be initialized by a constant expression}}
              ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/t5.cpp:7:10: note: subexpression not valid in a constant expression
  return templated<N>();  // expected-error {{no matching function for call to 'templated'}} 
         ^
/tmp/t5.cpp:13:5: note: in call to 'callTemplated()'
    callTemplated<0>(); // expected-note {{in call to 'callTemplated()'}} expected-note at -6 {{subexpression not valid in a constant expression}}
    ^
2 errors generated.
```




================
Comment at: clang/test/SemaTemplate/instantiate-function-params.cpp:1
 // RUN: %clang_cc1 -triple i686-unknown-unknown -fsyntax-only -verify %s
 
----------------
this test is very tricky, and hard for human to understand. It was added to test clang not crashing.

Different compilers (gcc, msvc) emit different diagnostics, with this patch, clang emits 3 more errs `no type named 'type'...`, it seems reasonable, and gcc also emits them.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79160/new/

https://reviews.llvm.org/D79160





More information about the cfe-commits mailing list