[PATCH] D64914: Implement P1771

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 23 09:10:30 PDT 2019


aaron.ballman added a comment.

In D64914#1595660 <https://reviews.llvm.org/D64914#1595660>, @erichkeane wrote:

> Rebased and did all the comments (including the www_status).  @aaron.ballman : Wasn't positive what you meant about the conversion functions, but I think I got one?


I was talking about [dcl.attr.nodiscard]p2.2: "an explicit type conversion (7.6.1.8 [expr.static.cast], 7.6.3 [expr.cast], 7.6.1.3 [expr.type.conv]) that constructs an object through a constructor declared nodiscard, or that initializes an object of a nodiscard type." and specifically the part about type conversion operators that are marked `nodiscard` directly.



================
Comment at: clang/include/clang/Basic/AttrDocs.td:1518
+    marked_ctor(); // diagnoses.
+    marked_ctor(3); // Does not diagnose, int constructor isn't marked nodiscard.
+  }
----------------
I think we may want to add a case like:
```
struct S {
  operator marked_type() const;
  [[nodiscard]] operator int() const;
};

void func() {
  S s;
  static_cast<marked_type>(s); // diagnoses
  (int)s; // diagnoses
}
```


================
Comment at: clang/lib/Sema/SemaDeclAttr.cpp:2835
+      D->getFunctionType()->getReturnType()->isVoidType() &&
+      !isa<CXXConstructorDecl>(D)) {
     S.Diag(AL.getLoc(), diag::warn_attribute_void_function_method) << AL << 0;
----------------
Conversion functions?


================
Comment at: clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp:100
+    S s;
+    (ConvertTo)s; // expected-warning {{expression result unused}}
+  }
----------------
If you specify a message on the `nodiscard` attribute used here, does the message get printed?


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

https://reviews.llvm.org/D64914





More information about the cfe-commits mailing list