[clang] Warning for incorrect useof 'pure' attribute (PR #78200)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 19 06:01:40 PST 2024


================
@@ -692,6 +692,13 @@ def warn_maybe_falloff_nonvoid_function : Warning<
 def warn_falloff_nonvoid_function : Warning<
   "non-void function does not return a value">,
   InGroup<ReturnType>;
+def warn_const_attr_with_pure_attr : Warning<
+  "'const' attribute imposes more restrictions, 'pure' attribute ignored">,
+  InGroup<IgnoredAttributes>;
+def warn_pure_function_returns_void : Warning<
+  "'%select{pure|const}0' attribute on function returning 'void', attribute ignored">,
+  InGroup<IgnoredAttributes>;
----------------
AaronBallman wrote:

```suggestion
def warn_const_attr_with_pure_attr : Warning<
  "'const' attribute imposes more restrictions; 'pure' attribute ignored">,
  InGroup<IgnoredAttributes>;
def warn_pure_function_returns_void : Warning<
  "'%select{pure|const}0' attribute on function returning 'void'; attribute ignored">,
  InGroup<IgnoredAttributes>;
```
minor nit for consistency with other related diagnostics.

Btw, to be explicit, I think it's reasonable that we do not reuse the usual "mutually exclusive attributes" functionality here because we have a very specific way to correct this situation whereas the usual behavior for mutual exclusion is that the first one wins. So adding a new diagnostic and using custom logic is appropriate IMO.

https://github.com/llvm/llvm-project/pull/78200


More information about the cfe-commits mailing list