summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/unittests/TweakTests.cpp
diff options
context:
space:
mode:
authorKadir Cetinkaya <kadircet@google.com>2019-10-01 10:39:14 +0200
committerKadir Cetinkaya <kadircet@google.com>2019-12-13 10:07:18 +0100
commit087528a331786228221d7a56a51ab97a3fcac8f1 (patch)
tree68766f303947d143e9501a2b256de36304ba9aaf /clang-tools-extra/clangd/unittests/TweakTests.cpp
parent7c13fe8a6a643497d49036e6ea368e1adb06f57e (diff)
downloadbcm5719-llvm-087528a331786228221d7a56a51ab97a3fcac8f1.tar.gz
bcm5719-llvm-087528a331786228221d7a56a51ab97a3fcac8f1.zip
[clangd] Add "inline" keyword to prevent ODR-violations in DefineInline
Reviewers: ilya-biryukov, hokein Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68261
Diffstat (limited to 'clang-tools-extra/clangd/unittests/TweakTests.cpp')
-rw-r--r--clang-tools-extra/clangd/unittests/TweakTests.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/unittests/TweakTests.cpp b/clang-tools-extra/clangd/unittests/TweakTests.cpp
index d50d27afb1c..ebeea82864c 100644
--- a/clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ b/clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -1864,6 +1864,66 @@ TEST_F(DefineInlineTest, QualifyWithUsingDirectives) {
EXPECT_EQ(apply(Test), Expected) << Test;
}
+TEST_F(DefineInlineTest, AddInline) {
+ llvm::StringMap<std::string> EditedFiles;
+ ExtraFiles["a.h"] = "void foo();";
+ apply(R"cpp(#include "a.h"
+ void fo^o() {})cpp", &EditedFiles);
+ EXPECT_THAT(EditedFiles, testing::ElementsAre(FileWithContents(
+ testPath("a.h"), "inline void foo(){}")));
+
+ // Check we put inline before cv-qualifiers.
+ ExtraFiles["a.h"] = "const int foo();";
+ apply(R"cpp(#include "a.h"
+ const int fo^o() {})cpp", &EditedFiles);
+ EXPECT_THAT(EditedFiles, testing::ElementsAre(FileWithContents(
+ testPath("a.h"), "inline const int foo(){}")));
+
+ // No double inline.
+ ExtraFiles["a.h"] = "inline void foo();";
+ apply(R"cpp(#include "a.h"
+ inline void fo^o() {})cpp", &EditedFiles);
+ EXPECT_THAT(EditedFiles, testing::ElementsAre(FileWithContents(
+ testPath("a.h"), "inline void foo(){}")));
+
+ // Constexprs don't need "inline".
+ ExtraFiles["a.h"] = "constexpr void foo();";
+ apply(R"cpp(#include "a.h"
+ constexpr void fo^o() {})cpp", &EditedFiles);
+ EXPECT_THAT(EditedFiles, testing::ElementsAre(FileWithContents(
+ testPath("a.h"), "constexpr void foo(){}")));
+
+ // Class members don't need "inline".
+ ExtraFiles["a.h"] = "struct Foo { void foo(); }";
+ apply(R"cpp(#include "a.h"
+ void Foo::fo^o() {})cpp", &EditedFiles);
+ EXPECT_THAT(EditedFiles,
+ testing::ElementsAre(FileWithContents(
+ testPath("a.h"), "struct Foo { void foo(){} }")));
+
+ // Function template doesn't need to be "inline"d.
+ ExtraFiles["a.h"] = "template <typename T> void foo();";
+ apply(R"cpp(#include "a.h"
+ template <typename T>
+ void fo^o() {})cpp", &EditedFiles);
+ EXPECT_THAT(EditedFiles,
+ testing::ElementsAre(FileWithContents(
+ testPath("a.h"), "template <typename T> void foo(){}")));
+
+ // Specializations needs to be marked "inline".
+ ExtraFiles["a.h"] = R"cpp(
+ template <typename T> void foo();
+ template <> void foo<int>();)cpp";
+ apply(R"cpp(#include "a.h"
+ template <>
+ void fo^o<int>() {})cpp", &EditedFiles);
+ EXPECT_THAT(EditedFiles,
+ testing::ElementsAre(FileWithContents(testPath("a.h"),
+ R"cpp(
+ template <typename T> void foo();
+ template <> inline void foo<int>(){})cpp")));
+}
+
TWEAK_TEST(DefineOutline);
TEST_F(DefineOutlineTest, TriggersOnFunctionDecl) {
FileName = "Test.cpp";
OpenPOWER on IntegriCloud