[clang] [Clang] Allow explicit member specialization to differ from template declaration wrt constexpr (PR #145272)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 24 10:58:12 PDT 2025


erichkeane wrote:

> This attempts to fix #26078. However I have couple of fundamental questions with the 7.1.5 consexpr note "[ Note: An explicit specialization can differ from the template declaration with respect to the constexpr specifier. — end note ]"

Current quote: https://eel.is/c++draft/dcl.constexpr#note-1 is the same.
> 
>     1. Does it also apply to member specializations which are not function templates themselves ? (as in the example https://godbolt.org/z/c4bYY8rxb)

I read that to do so, yes.  It applies to ALL templates.  An explicit specialization can change the constexpr/constevalness.

> 
>     2. if yes, then should it also apply to special member functions ? (constructors, destructors)

I would say yes, it should. Any templated SMFs also can have it changed with an explicit specialization.

This is actually related to a topic that came up for Reflection last week in EWG.  An 'explicit specialization' is a morally different 'entity'.  So it is allowed to change quite a bit more from the primary template than we might otherwise expect.  In this case, it is allowed to add/remove constexpr/consteval.

https://github.com/llvm/llvm-project/pull/145272


More information about the cfe-commits mailing list