[PATCH] D55552: [Sema] Better static assert diagnostics for expressions involving temporaries.

Arthur O'Dwyer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 11 07:05:33 PST 2018


Quuxplusone added inline comments.


================
Comment at: lib/Sema/SemaTemplate.cpp:3089
+      else
+        OS << "(";
+      for (CXXTemporaryObjectExpr::arg_iterator Arg = Node->arg_begin(),
----------------
It might be more maintainer-proof to write this as

    std::pair<const char *, const char *> Braces;
    if (Node->isStdInitListInitialization())
      Braces = std::make_pair("", "");
    else if (Node->isListInitialization())
      Braces = std::make_pair("{", "}");
    else
      Braces = std::make_pair("(", ")");
    OS << Braces.first;
    for (...) { ... }
    OS << Braces.second;
    return true;



================
Comment at: test/SemaCXX/static-assert.cpp:136
+static_assert(std::is_const<decltype(ExampleTypes(3))>::value, "message");
+// expected-error at -1{{static_assert failed due to requirement 'std::is_const<ExampleTypes>::value' "message"}}
 
----------------
Conspicuously missing any test for lines 3081–3106 above. IIUC, those lines would trigger on things like

```
template<class T> struct X { int i=0, j=0; constexpr operator bool() const { return false; } };
template<class T> void test() {
    static_assert(X<T>{});
    static_assert(X<T>{1,2});
    static_assert(T{0});
    static_assert(T(0));
}
template void test<int>();
```

But I guess I don't see why extra code is needed to handle those; shouldn't the pretty-printer handle them already? What do the current diagnostics look like for my example?


Repository:
  rC Clang

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

https://reviews.llvm.org/D55552





More information about the llvm-commits mailing list