Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b2cd98a

Browse files
committed
C++: Confirm correct behaviour on C++20
Making `constexpr` imply `const` was correct for C++11 and was a correct emulation of a GCC bug on GCC < 5.0. This test confirms that the problem isn't there in C++20.
1 parent cd8e9a1 commit b2cd98a

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// semmle-extractor-options: --edg --clang --edg --c++20
2+
3+
namespace cpp20 {
4+
5+
class TestConstexpr {
6+
constexpr int member_constexpr() { return 0; } // not const in C++ >= 14
7+
constexpr int member_const_constexpr() const { return 0; }
8+
};
9+
10+
} // namespace cpp20

cpp/ql/test/library-tests/specifiers2/specifiers2.expected

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
| Class | specifiers2pp.cpp:8:7:8:13 | MyClass | MyClass | abstract |
22
| Class | specifiers2pp.cpp:24:7:24:14 | MyClass2 | MyClass2 | abstract |
3+
| Function | cpp20.cpp:5:7:5:7 | operator= | operator= | extern |
4+
| Function | cpp20.cpp:5:7:5:7 | operator= | operator= | extern |
5+
| Function | cpp20.cpp:5:7:5:7 | operator= | operator= | inline |
6+
| Function | cpp20.cpp:5:7:5:7 | operator= | operator= | inline |
7+
| Function | cpp20.cpp:5:7:5:7 | operator= | operator= | is_constexpr |
8+
| Function | cpp20.cpp:5:7:5:7 | operator= | operator= | is_constexpr |
9+
| Function | cpp20.cpp:5:7:5:7 | operator= | operator= | public |
10+
| Function | cpp20.cpp:5:7:5:7 | operator= | operator= | public |
11+
| Function | cpp20.cpp:6:19:6:34 | member_constexpr | member_constexpr | declared_constexpr |
12+
| Function | cpp20.cpp:6:19:6:34 | member_constexpr | member_constexpr | inline |
13+
| Function | cpp20.cpp:6:19:6:34 | member_constexpr | member_constexpr | is_constexpr |
14+
| Function | cpp20.cpp:6:19:6:34 | member_constexpr | member_constexpr | private |
15+
| Function | cpp20.cpp:7:19:7:40 | member_const_constexpr | member_const_constexpr | const |
16+
| Function | cpp20.cpp:7:19:7:40 | member_const_constexpr | member_const_constexpr | declared_constexpr |
17+
| Function | cpp20.cpp:7:19:7:40 | member_const_constexpr | member_const_constexpr | inline |
18+
| Function | cpp20.cpp:7:19:7:40 | member_const_constexpr | member_const_constexpr | is_constexpr |
19+
| Function | cpp20.cpp:7:19:7:40 | member_const_constexpr | member_const_constexpr | private |
320
| Function | specifiers2.c:11:6:11:6 | f | f | extern |
421
| Function | specifiers2.c:12:13:12:13 | f | f | extern |
522
| Function | specifiers2.c:13:13:13:13 | f | f | extern |

cpp/ql/test/library-tests/specifiers2/specifiers2pp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ using Const_int = Const<int>;
6060
typedef volatile Const_int volatile_Const_int;
6161

6262
class TestConstexpr {
63-
constexpr int member_constexpr() { return 0; }
63+
constexpr int member_constexpr() { return 0; } // const in C++11
6464
constexpr int member_const_constexpr() const { return 0; }
6565
};

0 commit comments

Comments
 (0)