forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into amd-trunk-dev
- Loading branch information
Showing
748 changed files
with
22,924 additions
and
28,126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//===--- TemplateVirtualMemberFunctionCheck.cpp - clang-tidy --------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "TemplateVirtualMemberFunctionCheck.h" | ||
#include "clang/ASTMatchers/ASTMatchFinder.h" | ||
|
||
using namespace clang::ast_matchers; | ||
|
||
namespace clang::tidy::portability { | ||
namespace { | ||
AST_MATCHER(CXXMethodDecl, isUsed) { return Node.isUsed(); } | ||
} // namespace | ||
|
||
void TemplateVirtualMemberFunctionCheck::registerMatchers(MatchFinder *Finder) { | ||
Finder->addMatcher( | ||
cxxMethodDecl(ofClass(classTemplateSpecializationDecl( | ||
unless(isExplicitTemplateSpecialization())) | ||
.bind("specialization")), | ||
isVirtual(), unless(isUsed()), | ||
unless(cxxDestructorDecl(isDefaulted()))) | ||
.bind("method"), | ||
this); | ||
} | ||
|
||
void TemplateVirtualMemberFunctionCheck::check( | ||
const MatchFinder::MatchResult &Result) { | ||
const auto *ImplicitSpecialization = | ||
Result.Nodes.getNodeAs<ClassTemplateSpecializationDecl>("specialization"); | ||
const auto *MethodDecl = Result.Nodes.getNodeAs<CXXMethodDecl>("method"); | ||
|
||
diag(MethodDecl->getLocation(), | ||
"unspecified virtual member function instantiation; the virtual " | ||
"member function is not instantiated but it might be with a " | ||
"different compiler"); | ||
diag(ImplicitSpecialization->getPointOfInstantiation(), | ||
"template instantiated here", DiagnosticIDs::Note); | ||
} | ||
|
||
} // namespace clang::tidy::portability |
38 changes: 38 additions & 0 deletions
38
clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//===--- TemplateVirtualMemberFunctionCheck.h - clang-tidy ------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_TEMPLATEVIRTUALMEMBERFUNCTIONCHECK_H | ||
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_TEMPLATEVIRTUALMEMBERFUNCTIONCHECK_H | ||
|
||
#include "../ClangTidyCheck.h" | ||
|
||
namespace clang::tidy::portability { | ||
|
||
/// Upon instantiating a template class, non-virtual member functions don't have | ||
/// to be instantiated unless they are used. Virtual member function | ||
/// instantiation on the other hand is unspecified and depends on the | ||
/// implementation of the compiler. This check intends to find cases when a | ||
/// virtual member function is not instantiated but it might be with a different | ||
/// compiler. | ||
/// | ||
/// For the user-facing documentation see: | ||
/// http://clang.llvm.org/extra/clang-tidy/checks/portability/template-virtual-member-function.html | ||
class TemplateVirtualMemberFunctionCheck : public ClangTidyCheck { | ||
public: | ||
TemplateVirtualMemberFunctionCheck(StringRef Name, ClangTidyContext *Context) | ||
: ClangTidyCheck(Name, Context) {} | ||
void registerMatchers(ast_matchers::MatchFinder *Finder) override; | ||
void check(const ast_matchers::MatchFinder::MatchResult &Result) override; | ||
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { | ||
return LangOpts.CPlusPlus; | ||
} | ||
}; | ||
|
||
} // namespace clang::tidy::portability | ||
|
||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_TEMPLATEVIRTUALMEMBERFUNCTIONCHECK_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...s-extra/docs/clang-tidy/checks/portability/template-virtual-member-function.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.. title:: clang-tidy - portability-template-virtual-member-function | ||
|
||
portability-template-virtual-member-function | ||
============================================ | ||
|
||
Finds cases when an uninstantiated virtual member function in a template class causes | ||
cross-compiler incompatibility. | ||
|
||
Upon instantiating a template class, non-virtual member functions don't have to be | ||
instantiated unless they are used. Virtual member function instantiation on the other hand | ||
is unspecified and depends on the implementation of the compiler. | ||
|
||
In the following snippets the virtual member function is not instantiated by GCC and Clang, | ||
but it is instantiated by MSVC, so while the snippet is accepted by the former compilers, | ||
it is rejected by the latter. | ||
|
||
.. code:: c++ | ||
|
||
template<typename T> | ||
struct CrossPlatformError { | ||
virtual ~CrossPlatformError() = default; | ||
|
||
static void used() {} | ||
|
||
virtual void unused() { | ||
T MSVCError = this; | ||
}; | ||
}; | ||
|
||
int main() { | ||
CrossPlatformError<int>::used(); | ||
return 0; | ||
} | ||
|
||
Cross-platform projects that need to support MSVC on Windows might see compiler errors | ||
because certain virtual member functions are instantiated, which are not instantiated | ||
by other compilers on other platforms. This check highlights such virtual member functions. |
Oops, something went wrong.