This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [RFC] GCC 8 Project proposal: Extensions supporting C Metaprogramming, pseudo-templates
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Daniel Santos <daniel dot santos at pobox dot com>
- Cc: Allan Sandfeld Jensen <linux at carewolf dot com>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>, Joseph Myers <joseph at codesourcery dot com>, Richard Henderson <rth at redhat dot com>
- Date: Wed, 10 May 2017 10:24:21 +0100
- Subject: Re: [RFC] GCC 8 Project proposal: Extensions supporting C Metaprogramming, pseudo-templates
- Authentication-results: sourceware.org; auth=none
- References: <02f991c6-7679-9f9b-aa57-35a25e37acd9@pobox.com> <201705091529.53074.linux@carewolf.com> <58e1ace4-2285-3177-8939-2785c920b888@pobox.com>
On 10 May 2017 at 10:17, Daniel Santos wrote:
> Maybe "constexpr" would be a better name, as it mirrors the C++11 keyword.
> When I first read about C++ getting constexpr, my first thought was, "Yeah,
> as if they needed yet another way to do metaprogramming!" :) However, I
Because writing functions in normal C++ is much simpler and more
expressive than writing class templates and recursive partial
specializations.
Just because there's already one way to do something doesn't mean
better ways to do it are bad.
> hadn't gone so far as to investigate using this new attribute on functions
> since we already have __attribute__((const)). I haven't used this before so
> maybe I'm not aware of something that makes it unusable for such cases?
> Which of course raises the question if __attribute__((const)) would work out
> since it's only currently used on function declarations (and pointers to
> function declarations, but I don't fully understand what that is doing in
> handle_const_attribute).
__attribute__((const)) is not a substitute for constexpr, it's not
even in the same ballpark. It says the function doesn't touch global
memory, it doesn't mean its return value is a constant expression, so
you can't do:
int f() __attribute__((const));
int f() { return 1; }
int i[f()];
I don't think __attribute__((const)) is useful for your goal.