proxygen
PortabilityTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2012-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <folly/Portability.h>
18 
19 #if FOLLY_HAS_STRING_VIEW
20 #include <string_view> // @manual
21 #endif
22 
23 #include <memory>
24 
26 
27 class Base {
28  public:
29  virtual ~Base() {}
30  virtual int foo() const {
31  return 1;
32  }
33 };
34 
35 class Derived : public Base {
36  public:
37  int foo() const final {
38  return 2;
39  }
40 };
41 
42 // A compiler that supports final will likely inline the call to p->foo()
43 // in fooDerived (but not in fooBase) as it knows that Derived::foo() can
44 // no longer be overridden.
45 int fooBase(const Base* p) {
46  return p->foo() + 1;
47 }
48 int fooDerived(const Derived* p) {
49  return p->foo() + 1;
50 }
51 
52 TEST(Portability, Final) {
53  std::unique_ptr<Derived> p(new Derived);
54  EXPECT_EQ(3, fooBase(p.get()));
55  EXPECT_EQ(3, fooDerived(p.get()));
56 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
int fooDerived(const Derived *p)
virtual int foo() const
int fooBase(const Base *p)
TEST(Portability, Final)
AtomicCounter< T, DeterministicAtomic > Base
const
Definition: upload.py:398
virtual ~Base()
int foo() const final