1

The below example code fires the "testing" assert with gcc and clang, but not MSVC. Only when the line marked comment this out is commented out does it fire. With GCC and clang it fires both with and without that line. Is that expected?

#include <type_traits>

template <bool B>
constexpr void issue_error()
{
    static_assert(B, "testing");
};

int main()
{
    issue_error<false>();
    static_assert(std::is_same_v<int,char>,"!!"); // comment this out
}
  • It fails on [godbolt](https://www.godbolt.org/z/Gqhn4zndz). Oh. You mean it doesn't fire when the line is made a comment? Hm. – Peter - Reinstate Monica Jan 13 '22 at 10:32
  • 1
    I don't think the standard says anything about the order the compiler has to evaluate things. Apparently, if main() already fails at the first level MSVC doesn't bother to also compile the call to the next level. Should it? – BoP Jan 13 '22 at 10:38
  • 1
    Possible duplicate (is a bit old) https://stackoverflow.com/questions/5246049/c11-static-assert-and-template-instantiation – Richard Critten Jan 13 '22 at 10:40
  • 1
    gcc with -fmax-errors=1 behaves like MSVC. (Although MSVC does not by default stop after the first error, but perhaps it does with static assertions -- that would make some sense and save compile time for useless builds.) – Peter - Reinstate Monica Jan 13 '22 at 10:44
  • I am not sure, but it might be related to a bug I found last year: https://stackoverflow.com/q/66420107 – prapin Jan 13 '22 at 10:54
  • @RichardCritten That is about no possible valid instantiation, which clearly `issue_error` is. – Passer By Jan 13 '22 at 12:20

0 Answers0