[clang] Warning for incorrect useof 'pure' attribute (PR #78200)
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 15 18:23:01 PST 2024
================
@@ -11889,6 +11889,13 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD,
NewFD->setInvalidDecl();
}
+ if (NewFD->hasAttr<PureAttr>() || NewFD->hasAttr<ConstAttr>()) {
+ if (isa<CXXConstructorDecl>(NewFD))
+ Diag(NewFD->getLocation(), diag::warn_pure_attr_on_cxx_constructor);
+ else if (NewFD->getReturnType()->isVoidType())
+ Diag(NewFD->getLocation(), diag::warn_pure_function_returns_void);
----------------
ChuanqiXu9 wrote:
Then the title and the diagnostic might be confusing if the user are using `[[gnu::const]]`. You can look at the use of `%select` in `clang/include/clang/Basic/DiagnosticSemaKinds.td` to improve this. Also we need a test for `[[gnu::const]]` too.
https://github.com/llvm/llvm-project/pull/78200
More information about the cfe-commits
mailing list