diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2022-12-22 09:33:05 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2022-12-22 10:44:35 +0000 |
commit | 28f248a3397b50ae6047a7a907f5a159b1b1d310 (patch) | |
tree | 841dc57bb46fd3399efa62478a96d6103e00a39c /compilerplugins | |
parent | 00b2c42a838a95861cbba50bfeedc7afb10ff31c (diff) |
Make namespace checks look through LinkageSpecs
My clang-cl --with-visual-studio=2022preview build against VS 2022 Preview
17.5.0 Preview 2.0 had started to fail with
> [build CPT] compilerplugins/clang/test/getstr.cxx
> error: 'error' diagnostics expected but not seen:
> File compilerplugins/clang/test/getstr.cxx Line 42: directly use object of type '{{(rtl::)?}}OString' in a call of 'operator <<', instead of calling 'getStr' first [loplugin:getstr]
> File compilerplugins/clang/test/getstr.cxx Line 48: directly use object of type 'S' (aka 'rtl::OString') in a call of 'operator <<', instead of calling 'getStr' first [loplugin:getstr]
> File compilerplugins/clang/test/getstr.cxx Line 49: directly use object of type 'rtl::OString' in a call of 'operator <<', instead of calling 'getStr' first [loplugin:getstr]
> File compilerplugins/clang/test/getstr.cxx Line 55: directly use object of type 'rtl::OString' in a call of 'operator <<', instead of calling 'getStr' first [loplugin:getstr]
> File compilerplugins/clang/test/getstr.cxx Line 57: directly use object of type '{{(rtl::)?}}OString' in a call of 'operator <<', instead of calling 'getStr' first [loplugin:getstr]
> 5 errors generated.
apparently because
C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/MSVC/14.35.32124/include/ostream
now contains
[...]
> _EXPORT_STD extern "C++" template <class _Elem, class _Traits>
> class basic_ostream : virtual public basic_ios<_Elem, _Traits> { // control insertions into a stream buffer
[...]
with a wrapping extern "C++", so the call to StdNamespace() in
> if (!loplugin::TypeCheck(expr->getArg(0)->getType())
> .ClassOrStruct("basic_ostream")
> .StdNamespace()) //TODO: check template args
in compilerplugins/clang/getstr.cxx no longer matched
Change-Id: Iaeb461d5aa855a8602c5c6f791407c08a1c5d309
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144735
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/check.cxx | 13 | ||||
-rw-r--r-- | compilerplugins/clang/check.hxx | 4 |
2 files changed, 13 insertions, 4 deletions
diff --git a/compilerplugins/clang/check.cxx b/compilerplugins/clang/check.cxx index 93fd7c7f7307..7be98bf97d5c 100644 --- a/compilerplugins/clang/check.cxx +++ b/compilerplugins/clang/check.cxx @@ -202,7 +202,7 @@ TerminalCheck ContextCheck::GlobalNamespace() const { TerminalCheck ContextCheck::StdNamespace() const { return TerminalCheck( - context_ != nullptr && context_->isStdNamespace()); + context_ != nullptr && lookThroughLinkageSpec()->isStdNamespace()); } namespace { @@ -224,15 +224,22 @@ bool isStdOrNestedNamespace(clang::DeclContext const * context) { } TerminalCheck ContextCheck::StdOrNestedNamespace() const { - return TerminalCheck(context_ != nullptr && isStdOrNestedNamespace(context_)); + return TerminalCheck(context_ != nullptr && isStdOrNestedNamespace(lookThroughLinkageSpec())); } ContextCheck ContextCheck::AnonymousNamespace() const { - auto n = llvm::dyn_cast_or_null<clang::NamespaceDecl>(context_); + auto n = llvm::dyn_cast_or_null<clang::NamespaceDecl>(lookThroughLinkageSpec()); return ContextCheck( n != nullptr && n->isAnonymousNamespace() ? n->getParent() : nullptr); } +clang::DeclContext const * ContextCheck::lookThroughLinkageSpec() const { + if (context_ != nullptr && context_->getDeclKind() == clang::Decl::LinkageSpec) { + return context_->getParent(); + } + return context_; +} + namespace { bool BaseCheckNotSomethingInterestingSubclass(const clang::CXXRecordDecl *BaseDefinition) { diff --git a/compilerplugins/clang/check.hxx b/compilerplugins/clang/check.hxx index 9c35acff7b5e..4ac311759832 100644 --- a/compilerplugins/clang/check.hxx +++ b/compilerplugins/clang/check.hxx @@ -140,6 +140,8 @@ public: explicit ContextCheck(const clang::NamespaceDecl * decl ) : context_( decl ) {} private: + clang::DeclContext const * lookThroughLinkageSpec() const; + clang::DeclContext const * const context_; }; @@ -277,7 +279,7 @@ ContextCheck DeclCheck::Var(llvm::StringRef id) const ContextCheck ContextCheck::Namespace(llvm::StringRef id) const { if (context_) { - auto n = llvm::dyn_cast<clang::NamespaceDecl>(context_); + auto n = llvm::dyn_cast<clang::NamespaceDecl>(lookThroughLinkageSpec()); if (n != nullptr) { auto const i = n->getIdentifier(); if (i != nullptr && i->getName() == id) { |