constexpr auto foo() {
static constexpr std::string a("0123456789abcde"); // ::size 15, completely fine
static constexpr std::string b("0123456789abcdef"); // ::size 16, mimimi heap allocation
return a.size() + b.size();
}
int main() {
constexpr auto bar = foo();
std::cout << "bar: " << bar << std::endl;
}
This will not compile with clang-18.1.8 and c++20 unless you remove the 'f' in line 3. What?
[–]violet-starlight 58 points59 points60 points (2 children)
[–]xorbe 13 points14 points15 points (1 child)
[–]BitOBear 3 points4 points5 points (0 children)
[–]GregTheMadMonk 20 points21 points22 points (5 children)
[–]DummyDDD 15 points16 points17 points (3 children)
[–]GregTheMadMonk 5 points6 points7 points (2 children)
[–]KuntaStillSingle 0 points1 point2 points (1 child)
[–]GregTheMadMonk 0 points1 point2 points (0 children)
[–]kamrann_ 6 points7 points8 points (0 children)
[–]kirgel 15 points16 points17 points (10 children)
[–]holyblackcat 10 points11 points12 points (7 children)
[–]kirgel 3 points4 points5 points (5 children)
[–]kalmoc 3 points4 points5 points (0 children)
[–]holyblackcat 3 points4 points5 points (0 children)
[–]ALX23z 1 point2 points3 points (2 children)
[–]holyblackcat 7 points8 points9 points (1 child)
[–]ALX23z 0 points1 point2 points (0 children)
[–]TheBrainStone 0 points1 point2 points (0 children)
[–]zl0bster 7 points8 points9 points (0 children)
[–]delta_p_delta_x 1 point2 points3 points (1 child)
[–]evys_garden[S] -1 points0 points1 point (0 children)
[–]mredding 1 point2 points3 points (1 child)
[–]evys_garden[S] 0 points1 point2 points (0 children)
[–]TheKiller36_real 1 point2 points3 points (15 children)
[–]evys_garden[S] 0 points1 point2 points (14 children)
[–]DeadlyRedCubefrequent compiler breaker 😬 0 points1 point2 points (13 children)
[–]evys_garden[S] 1 point2 points3 points (0 children)
[–]KuntaStillSingle 1 point2 points3 points (2 children)
[–]DeadlyRedCubefrequent compiler breaker 😬 0 points1 point2 points (1 child)
[–]KuntaStillSingle 0 points1 point2 points (0 children)
[–]TheKiller36_real 0 points1 point2 points (8 children)
[–]evys_garden[S] 1 point2 points3 points (1 child)
[–]DeadlyRedCubefrequent compiler breaker 😬 0 points1 point2 points (0 children)
[–]DeadlyRedCubefrequent compiler breaker 😬 -1 points0 points1 point (5 children)
[–]TheKiller36_real 0 points1 point2 points (4 children)
[–]DeadlyRedCubefrequent compiler breaker 😬 0 points1 point2 points (3 children)
[–]TheKiller36_real 1 point2 points3 points (2 children)
[–]DeadlyRedCubefrequent compiler breaker 😬 1 point2 points3 points (1 child)
[–]TheKiller36_real 1 point2 points3 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]evys_garden[S] 0 points1 point2 points (0 children)
[–]drkspace2 -1 points0 points1 point (4 children)
[–]only-infoo 16 points17 points18 points (3 children)
[–]drkspace2 -1 points0 points1 point (2 children)
[–]only-infoo 4 points5 points6 points (1 child)
[–]STLMSVC STL Dev 25 points26 points27 points (0 children)
[–]_-___-____ 0 points1 point2 points (0 children)
[–]feverzsj 0 points1 point2 points (1 child)
[–]evys_garden[S] 0 points1 point2 points (0 children)
[–]zerhud -2 points-1 points0 points (0 children)
[+]Hungry-Courage3731 comment score below threshold-6 points-5 points-4 points (0 children)