Is there any construct valid since C++98 that behaves differently in C++20 and C++23?

13 hours ago 1
ARTICLE AD BOX

Just for fun, I'm trying to write a program that detects C++ version based purely on syntactic quirks between standards. I've managed to piece together solutions for all but the newest standard.

#include <iostream> #include <string> #define u8 "\x01" #define M(x, ...) __VA_ARGS__ struct B {}; struct A { bool operator==(B const&); }; bool A::operator ==(B const&) { return false; } bool operator==(B const&, A const&) { return true; } int main() { int m[] = { M(1'2, 3'4, 5) }; B b; A a; // C++98's preprocessor substitutes the u8 we #define'd; // later standards see it as starting a Unicode string. // https://stackoverflow.com/a/6402166/29080386 if (u8"\0"[0]) { std::cout << "C++98" << std::endl; // C++14 introduced the ' character as a digit separator; // earlier standards interpret it as a character literal // regardless of context. // https://stackoverflow.com/a/23980931/29080386 } else if (m[0] == 5) { std::cout << "C++11" << std::endl; // C++14 was the last to support trigraphs. // It will interpret ??= as "#"; later standards see '?'. } else if ("??="[0] == '#') { std::cout << "C++14" << std::endl; // C++17 calls the function; C++20 calls the method. // https://stackoverflow.com/q/64130311/29080386 } else if (b == a) { std::cout << "C++17" << std::endl; } else { std::cout << "C++20" << std::endl; } return 0; }

I haven't been able to find any such valid but breaking changes in C++23. Are there any?

Read Entire Article