C++ Logo


Advanced search

Re: Explicit instantiation declarations and requires clauses

From: Krystian Stasiowski <sdkrystian_at_[hidden]>
Date: Sat, 28 Sep 2019 12:55:58 -0400
See http://eel.is/c++draft/temp.names#8
-------- Original message --------From: Christopher Head via Std-Discussion <std-discussion_at_[hidden]> Date: 9/28/19 12:24 (GMT-05:00) To: std-discussion_at_[hidden] Cc: Christopher Head <chead_at_[hidden]> Subject: Re: [std-discussion] Explicit instantiation declarations and requires clauses On Sun, 8 Sep 2019 09:54:50 -0700Christopher Head <chead_at_[hidden]> wrote:> Hi folks,> From reading the standard draft, I’m reasonably certain (though could> be wrong—please correct me if so) that, if a template has a requires> clause, the requires clause is checked for an explicit instantiation> declaration. GCC also seems to work this way (and is the only compiler> I have access to that supports concepts at all, so is the only one I> could test).> > Why is this so? It seems to me that it’s both unnecessary and also> somewhat annoying.> > It’s unnecessary, as far as I can see, because any program containing> an explicit instantiation declaration, assuming that specialization is> used anywhere, must also contain a matching explicit instantiation> definition in some translation unit; therefore, to ensure that the> requires clause is checked properly, it would be sufficient (in the> sense that the constraint would be checked somewhere and the program> as a whole would fail to compile on constraint violation) to check the> requirements at the point of explicit instantiation definition, while> ignoring them at the explicit instantiation declaration.> > It’s annoying because it means an explicit instantiation declaration> can no longer use an incomplete type as a template parameter, which> used to be possible in the absence of a requires clause (the explicit> instantiation definition would typically require a complete type> because the template being instantiated would typically need the type> to be complete in order to do interesting things with it, but the> explicit instantiation declaration may not—for example, a class> template whose class body doesn’t require a complete type but whose> function bodies do, and whose function bodies are provided in a single> translation unit rather than in a header file, should be able to use> an incomplete type in the header file and a complete type in the> source file).> > Can anyone explain if (1) I have understood the situation correctly,> and (2) there is any reason why explicit instantiation declarations> need to check requires clauses?> > Thank you!Anyone have any thoughts on this?-- Christopher Head-- Std-Discussion mailing listStd-Discussion_at_[hidden]://lists.isocpp.org/mailman/listinfo.cgi/std-discussion

Received on 2019-09-28 11:58:12