File tree 1 file changed +16
-23
lines changed
1 file changed +16
-23
lines changed Original file line number Diff line number Diff line change 879
879
880
880
\begin {example }
881
881
\begin {codeblock }
882
- constexpr int square(int x)
883
- { return x * x; } // OK
884
- constexpr long long_max()
885
- { return 2147483647; } // OK
886
- constexpr int abs(int x) {
887
- if (x < 0)
888
- x = -x;
889
- return x; // OK
882
+ constexpr int square(int x) { // OK
883
+ return x * x;
890
884
}
891
- constexpr int constant_non_42(int n) { // OK
892
- if (n == 42) {
893
- static int value = n;
894
- return value;
895
- }
896
- return n;
885
+ constexpr std::generator<int> iota(int n = 0) {
886
+ while (true) co_yield n++; // error: \tcode {co_yield} cannot be used in a constexpr function
897
887
}
898
- constexpr int uninit( ) {
899
- struct { int a; } s;
900
- return s.a; // error: uninitialized read of \tcode {s.a}
888
+ constexpr int not_really_constexpr(int n ) { // constexpr-usable function, but calls to
889
+ static int value = n; // \tcode {not_really_constexpr} never produce a constant expression
890
+ return value;
901
891
}
902
- constexpr int prev(int x)
903
- { return --x; } // OK
904
- constexpr int g(int x, int n) { // OK
905
- int r = 1;
906
- while (--n > 0) r *= x;
907
- return r;
892
+ constexpr int uninit() { // constexpr-usable function, but a program which calls
893
+ struct { int a; } s; // \tcode {uninit} in a constant expression is ill-formed
894
+ return s.a;
908
895
}
896
+ struct Base {
897
+ constexpr Derived() = default; // OK
898
+ };
899
+ struct Derived : virtual Base {
900
+ constexpr Derived() = default; // error: constructor cannot be constexpr in a
901
+ }; // class or struct with virtual base classes
909
902
\end {codeblock }
910
903
\end {example }
911
904
You can’t perform that action at this time.
0 commit comments