C++11 static_assert and template instantiation

后端 未结 5 1085
执念已碎
执念已碎 2020-11-29 03:41

In C++11, should the operation of static_assert within a template depend on whether that template has been instantiated or not? For example, with the following code

5条回答
  •  一个人的身影
    2020-11-29 04:30

    This is 14.6.2 section in C++ standard.

    Your static_assert is related to support binding nondependent names when initially parsing a template. The Digital Mars Compiler does not currently support binding nondependent names. GCC 4.5.0 does support binding nondependent names.

    If your expression does not depend on the template parameters then such expression is known when initially parsing a template. Compiler must show the error message. GCC 4.5.0 does it.

    Replace your 0 in static_assert with I*I < 0, for expample and you get dependent name. Error message will appear for the case of uninstantiated template only.

提交回复
热议问题