This is the mail archive of the
mailing list for the GCC project.
Re: [RFC] GCC 8 Project proposal: Extensions supporting C Metaprogramming, pseudo-templates
- From: Florian Weimer <fweimer at redhat dot com>
- To: Daniel Santos <daniel dot santos at pobox dot com>, gcc <gcc at gcc dot gnu dot org>, Joseph Myers <joseph at codesourcery dot com>, Richard Henderson <rth at redhat dot com>
- Date: Tue, 9 May 2017 11:36:31 +0200
- Subject: Re: [RFC] GCC 8 Project proposal: Extensions supporting C Metaprogramming, pseudo-templates
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=fweimer at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E9C43C059730
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E9C43C059730
- References: <firstname.lastname@example.org>
On 05/09/2017 01:36 AM, Daniel Santos wrote:
To further the usefulness of such techniques, I propose the addition of
a c-family attribute to declare a parameter, variable (and possibly
other declarations) as "constprop" or some similar word. The purpose of
the attribute is to:
1.) Emit a warning or error when the value is not optimized away, and
2.) Direct various optimization passes to prefer (or force) either
cloning or inlining of a function with such a parameter.
I think GCC used to treat C and C++ constant expressions this way in the
old days. That is, what was a constant expression depended to some
degree on the capabilities of the folder at least (and maybe the
optimizers). This wasn't such a great idea because it made behavior
inconsistent across architectures and GCC versions.
There are also thorny specification issues, like is an array whose
length is a constprop value a VLA or not?
If you are interested in metaprogramming techniques, you are probably
better off writing code generators or using a C++ subset.