10#include "gtest/gtest.h"
16class OverridePureVirtualsTests :
public TweakTest {
18 OverridePureVirtualsTests() : TweakTest(
"OverridePureVirtuals") {}
21TEST_F(OverridePureVirtualsTests, MinimalUnavailable) {
25TEST_F(OverridePureVirtualsTests, MinimalAvailable) {
27class B { public: virtual void Foo() = 0; };
28class ^C : public B {};
32TEST_F(OverridePureVirtualsTests, UnavailableWhenOverriden) {
37 virtual void foo() = 0;
47TEST_F(OverridePureVirtualsTests, AvailabilityNoOverride) {
51virtual ~Base() = default;
56class ^Derived : public Base {
63TEST_F(OverridePureVirtualsTests, AvailabilityPartiallyOverridden) {
67virtual ~Base() = default;
72class ^Derived : public Base {
79TEST_F(OverridePureVirtualsTests, EmptyDerivedClass) {
80 const char *Before = R
"cpp(
83virtual ~Base() = default;
85virtual void F2(int P1, const int &P2) = 0;
88class ^Derived : public Base {};
90 const auto *Expected = R
"cpp(
93virtual ~Base() = default;
95virtual void F2(int P1, const int &P2) = 0;
98class Derived : public Base {
101 // TODO: Implement this pure virtual method.
102 static_assert(false, "Method `F1` is not implemented.");
105 void F2(int P1, const int & P2) override {
106 // TODO: Implement this pure virtual method.
107 static_assert(false, "Method `F2` is not implemented.");
111 auto Applied = apply(Before);
112 EXPECT_EQ(Expected, Applied) <<
"Applied result:\n" << Applied;
115TEST_F(OverridePureVirtualsTests, SingleBaseClassPartiallyImplemented) {
116 auto Applied = apply(
120virtual ~Base() = default;
121virtual void F1() = 0;
122virtual void F2() = 0;
125class ^Derived : public Base {
131 const auto *Expected = R
"cpp(
134virtual ~Base() = default;
135virtual void F1() = 0;
136virtual void F2() = 0;
139class Derived : public Base {
142 // TODO: Implement this pure virtual method.
143 static_assert(false, "Method `F2` is not implemented.");
149 EXPECT_EQ(Applied, Expected) << "Applied result:\n" << Applied;
152TEST_F(OverridePureVirtualsTests, MultipleDirectBaseClasses) {
153 const char *Before = R
"cpp(
156 virtual void func1() = 0;
160 virtual bool func2(char c) const = 0;
163class ^Derived : public Base1, public Base2 {};
165 const auto *Expected = R
"cpp(
168 virtual void func1() = 0;
172 virtual bool func2(char c) const = 0;
175class Derived : public Base1, public Base2 {
177 void func1() override {
178 // TODO: Implement this pure virtual method.
179 static_assert(false, "Method `func1` is not implemented.");
182 bool func2(char c) const override {
183 // TODO: Implement this pure virtual method.
184 static_assert(false, "Method `func2` is not implemented.");
188 auto Applied = apply(Before);
189 EXPECT_EQ(Expected, Applied) <<
"Applied result:\n" << Applied;
192TEST_F(OverridePureVirtualsTests, UnnamedParametersInBase) {
193 const char *Before = R
"cpp(
197 virtual void func(int, const S&, char*) = 0;
200class ^Derived : public Base {};
203 const auto *Expected = R
"cpp(
207 virtual void func(int, const S&, char*) = 0;
210class Derived : public Base {
212 void func(int, const S &, char *) override {
213 // TODO: Implement this pure virtual method.
214 static_assert(false, "Method `func` is not implemented.");
218 auto Applied = apply(Before);
219 EXPECT_EQ(Expected, Applied) <<
"Applied result:\n" << Applied;
222TEST_F(OverridePureVirtualsTests, DiamondInheritance) {
223 const char *Before = R
"cpp(
226 virtual ~Top() = default;
227 virtual void diamond_func() = 0;
229class Left : virtual public Top {};
230class Right : virtual public Top {};
231class ^Bottom : public Left, public Right {};
233 const auto *Expected = R
"cpp(
236 virtual ~Top() = default;
237 virtual void diamond_func() = 0;
239class Left : virtual public Top {};
240class Right : virtual public Top {};
241class Bottom : public Left, public Right {
243 void diamond_func() override {
244 // TODO: Implement this pure virtual method.
245 static_assert(false, "Method `diamond_func` is not implemented.");
249 auto Applied = apply(Before);
250 EXPECT_EQ(Expected, Applied) <<
"Applied result:\n" << Applied;
253TEST_F(OverridePureVirtualsTests, MixedAccessSpecifiers) {
254 const char *Before = R
"cpp(
257 virtual void pub_func() = 0;
258 virtual void pub_func2(char) const = 0;
260 virtual int prot_func(int x) const = 0;
263class ^Derived : public Base {
264 int member; // Existing member
266 Derived(int m) : member(m) {}
269 const auto *Expected = R
"cpp(
272 virtual void pub_func() = 0;
273 virtual void pub_func2(char) const = 0;
275 virtual int prot_func(int x) const = 0;
278class Derived : public Base {
279 int member; // Existing member
281 void pub_func() override {
282 // TODO: Implement this pure virtual method.
283 static_assert(false, "Method `pub_func` is not implemented.");
286 void pub_func2(char) const override {
287 // TODO: Implement this pure virtual method.
288 static_assert(false, "Method `pub_func2` is not implemented.");
291 Derived(int m) : member(m) {}
294 int prot_func(int x) const override {
295 // TODO: Implement this pure virtual method.
296 static_assert(false, "Method `prot_func` is not implemented.");
300 auto Applied = apply(Before);
301 EXPECT_EQ(Expected, Applied) <<
"Applied result:\n" << Applied;
304TEST_F(OverridePureVirtualsTests, OutOfOrderMixedAccessSpecifiers) {
305 const char *Before = R
"cpp(
308 virtual void pub_func() = 0;
309 virtual void pub_func2(char) const = 0;
311 virtual int prot_func(int x) const = 0;
314class ^Derived : public Base {
315 int member; // Existing member
319 Derived(int m) : member(m) {}
322 const auto *Expected = R
"cpp(
325 virtual void pub_func() = 0;
326 virtual void pub_func2(char) const = 0;
328 virtual int prot_func(int x) const = 0;
331class Derived : public Base {
332 int member; // Existing member
334 int prot_func(int x) const override {
335 // TODO: Implement this pure virtual method.
336 static_assert(false, "Method `prot_func` is not implemented.");
341 void pub_func() override {
342 // TODO: Implement this pure virtual method.
343 static_assert(false, "Method `pub_func` is not implemented.");
346 void pub_func2(char) const override {
347 // TODO: Implement this pure virtual method.
348 static_assert(false, "Method `pub_func2` is not implemented.");
351 Derived(int m) : member(m) {}
354 auto Applied = apply(Before);
355 EXPECT_EQ(Expected, Applied) <<
"Applied result:\n" << Applied;
358TEST_F(OverridePureVirtualsTests, MultiAccessSpecifiersOverride) {
359 constexpr auto Before = R
"cpp(
362 virtual void foo() = 0;
364 virtual void bar() = 0;
367class ^Derived : public Base {};
370 constexpr auto Expected = R
"cpp(
373 virtual void foo() = 0;
375 virtual void bar() = 0;
378class Derived : public Base {
380 void foo() override {
381 // TODO: Implement this pure virtual method.
382 static_assert(false, "Method `foo` is not implemented.");
385 void bar() override {
386 // TODO: Implement this pure virtual method.
387 static_assert(false, "Method `bar` is not implemented.");
391 auto Applied = apply(Before);
392 EXPECT_EQ(Expected, Applied) <<
"Applied result:\n" << Applied;
395TEST_F(OverridePureVirtualsTests, AccessSpecifierAlreadyExisting) {
396 const char *Before = R
"cpp(
399 virtual void func1() = 0;
402class ^Derived : public Base {
407 const auto *Expected = R
"cpp(
410 virtual void func1() = 0;
413class Derived : public Base {
415 void func1() override {
416 // TODO: Implement this pure virtual method.
417 static_assert(false, "Method `func1` is not implemented.");
422 auto Applied = apply(Before);
423 EXPECT_EQ(Expected, Applied) <<
"Applied result:\n" << Applied;
426TEST_F(OverridePureVirtualsTests, ConstexprSpecifier) {
427 ExtraArgs.push_back(
"-std=c++20");
429 constexpr auto Before = R
"cpp(
432 constexpr virtual int getValue() const = 0;
435class ^D : public B {};
438 constexpr auto Expected = R
"cpp(
441 constexpr virtual int getValue() const = 0;
446 constexpr int getValue() const override {
447 // TODO: Implement this pure virtual method.
448 static_assert(false, "Method `getValue` is not implemented.");
452 auto Applied = apply(Before);
453 EXPECT_EQ(Expected, Applied) <<
"Applied result:\n" << Applied;
456TEST_F(OverridePureVirtualsTests, ConstevalSpecifier) {
457 ExtraArgs.push_back(
"-std=c++20");
459 constexpr auto Before = R
"cpp(
462 virtual consteval float calculate() = 0;
465class ^D : public B {};
468 constexpr auto Expected = R
"cpp(
471 virtual consteval float calculate() = 0;
476 consteval float calculate() override {
477 // TODO: Implement this pure virtual method.
478 static_assert(false, "Method `calculate` is not implemented.");
482 auto Applied = apply(Before);
483 EXPECT_EQ(Expected, Applied) <<
"Applied result:\n" << Applied;
486TEST_F(OverridePureVirtualsTests, LValueRefQualifier) {
487 constexpr auto Before = R
"cpp(
490 virtual void process() & = 0;
493class ^D : public B {};
496 constexpr auto Expected = R
"cpp(
499 virtual void process() & = 0;
504 void process() & override {
505 // TODO: Implement this pure virtual method.
506 static_assert(false, "Method `process` is not implemented.");
510 auto Applied = apply(Before);
511 EXPECT_EQ(Expected, Applied) <<
"Applied result:\n" << Applied;
514TEST_F(OverridePureVirtualsTests, RValueRefQualifier) {
515 constexpr auto Before = R
"cpp(
518 virtual bool isValid() && = 0;
521class ^D : public B {};
524 constexpr auto Expected = R
"cpp(
527 virtual bool isValid() && = 0;
532 bool isValid() && override {
533 // TODO: Implement this pure virtual method.
534 static_assert(false, "Method `isValid` is not implemented.");
538 auto Applied = apply(Before);
539 EXPECT_EQ(Expected, Applied) <<
"Applied result:\n" << Applied;
542TEST_F(OverridePureVirtualsTests, SimpleTrailingReturnType) {
543 constexpr auto Before = R
"cpp(
546 virtual auto getStatus() -> bool = 0;
549class ^D : public B {};
552 constexpr auto Expected = R
"cpp(
555 virtual auto getStatus() -> bool = 0;
560 auto getStatus() -> bool override {
561 // TODO: Implement this pure virtual method.
562 static_assert(false, "Method `getStatus` is not implemented.");
566 auto Applied = apply(Before);
567 EXPECT_EQ(Expected, Applied) <<
"Applied result:\n" << Applied;
570TEST_F(OverridePureVirtualsTests, ConstexprLValueRefAndTrailingReturn) {
571 ExtraArgs.push_back(
"-std=c++20");
573 constexpr auto Before = R
"cpp(
576 constexpr virtual auto getData() & -> const char * = 0;
579class ^D : public B {};
582 constexpr auto Expected = R
"cpp(
585 constexpr virtual auto getData() & -> const char * = 0;
590 constexpr auto getData() & -> const char * override {
591 // TODO: Implement this pure virtual method.
592 static_assert(false, "Method `getData` is not implemented.");
596 auto Applied = apply(Before);
597 EXPECT_EQ(Expected, Applied) <<
"Applied result:\n" << Applied;
600TEST_F(OverridePureVirtualsTests, ConstevalRValueRefAndTrailingReturn) {
601 ExtraArgs.push_back(
"-std=c++20");
603 constexpr auto Before = R
"cpp(
606 virtual consteval auto foo() && -> double = 0;
609class ^D : public B {};
612 constexpr auto Expected = R
"cpp(
615 virtual consteval auto foo() && -> double = 0;
620 consteval auto foo() && -> double override {
621 // TODO: Implement this pure virtual method.
622 static_assert(false, "Method `foo` is not implemented.");
626 auto Applied = apply(Before);
627 EXPECT_EQ(Expected, Applied) <<
"Applied result:\n" << Applied;
630TEST_F(OverridePureVirtualsTests, CombinedFeaturesWithTrailingReturnTypes) {
631 ExtraArgs.push_back(
"-std=c++20");
633 constexpr auto Before = R
"cpp(
636 virtual auto f1() & -> int = 0;
637 constexpr virtual auto f2() && -> int = 0;
638 virtual consteval auto f3() -> int = 0;
639 virtual auto f4() const & -> char = 0;
640 constexpr virtual auto f5() const && -> bool = 0;
643class ^D : public B {};
646 constexpr auto Expected = R
"cpp(
649 virtual auto f1() & -> int = 0;
650 constexpr virtual auto f2() && -> int = 0;
651 virtual consteval auto f3() -> int = 0;
652 virtual auto f4() const & -> char = 0;
653 constexpr virtual auto f5() const && -> bool = 0;
658 auto f1() & -> int override {
659 // TODO: Implement this pure virtual method.
660 static_assert(false, "Method `f1` is not implemented.");
663 constexpr auto f2() && -> int override {
664 // TODO: Implement this pure virtual method.
665 static_assert(false, "Method `f2` is not implemented.");
668 consteval auto f3() -> int override {
669 // TODO: Implement this pure virtual method.
670 static_assert(false, "Method `f3` is not implemented.");
673 auto f4() const & -> char override {
674 // TODO: Implement this pure virtual method.
675 static_assert(false, "Method `f4` is not implemented.");
678 constexpr auto f5() const && -> bool override {
679 // TODO: Implement this pure virtual method.
680 static_assert(false, "Method `f5` is not implemented.");
684 auto Applied = apply(Before);
685 EXPECT_EQ(Expected, Applied) <<
"Applied result:\n" << Applied;
688TEST_F(OverridePureVirtualsTests, DefaultParameters) {
689 ExtraArgs.push_back(
"-std=c++20");
691 constexpr auto Before = R
"cpp(
694 virtual void foo(int var = 0) = 0;
697class ^D : public B {};
700 constexpr auto Expected = R
"cpp(
703 virtual void foo(int var = 0) = 0;
708 void foo(int var = 0) override {
709 // TODO: Implement this pure virtual method.
710 static_assert(false, "Method `foo` is not implemented.");
714 auto Applied = apply(Before);
715 EXPECT_EQ(Expected, Applied) <<
"Applied result:\n" << Applied;
#define EXPECT_AVAILABLE(MarkedCode)
#define EXPECT_UNAVAILABLE(MarkedCode)
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
TEST_F(BackgroundIndexTest, NoCrashOnErrorFile)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//