Take the following code:
#include <array>
constexpr std::array<int, 10> a{};
static_assert(std::next(std::begin(a)) == std::begin(a) + 1);
With -std=c++17 GCC compiles it flawlessly, but Clang complains that the expression is not an integral constant expression. It looks like that the problem is about the std::next which, however, should be constexpr in C++17.
Nevertheless, std::next is in the std library, not in the compiler itself, therefore there is something weird going on. And just to make things even better, the example compiles perfectly if you pass -stdlib=libc++ to Clang.
What is going on? Who is wrong and who is right?
EDIT
The issue seems to be related to clang being toolchain-ed against GCC 7.2 inside godbolt. If you add the --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot parameter to the command line, everything works flawlessly. (Thanks to @einpoklum who reported the issue to godbolt -- I have been slower ;) )
EDIT
For everyone who consider that an old compiler should work for actual standard, sorry to say that the consideration is meaningless. I am talking about the last versions of both GCC and Clang. And the problem is reproducible with the trunk version of both. Older compilers are not relevant for this question (MSVC behaviour would be interesting, instead).
std::nextarguments are (can be) evaluated during run time whereasstatic_assertexpects a strictlyconstexprcondition. Just because the function is marked asconstexprdoesn't mean it can't be invoked as a regular function. - Ronaand thestd::beginareconstexpr, so it is fine -- everything markedconstexprcan be evaluated at runtime, not the opposite - dodomorandistatic_assert(std::begin(a) != std::end(a))should not compile, but it works flawlessly... - dodomorandiiterator.operator+()aconstexprmethod? - underscore_d