This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [3.4 PATCH] PR c++/20995: Type-unsafe trees for templates
- From: Gabriel Dos Reis <gdr at cs dot tamu dot edu>
- To: Roger Sayle <roger at eyesopen dot com>
- Cc: Mark Mitchell <mark at codesourcery dot com>, gcc-patches at gcc dot gnu dot org
- Date: 25 Apr 2005 06:21:13 -0500
- Subject: Re: [3.4 PATCH] PR c++/20995: Type-unsafe trees for templates
- Organization: Texas A&M University, Department of Computer Science
- References: <Pine.LNX.4.44.0504241840410.13006-100000@www.eyesopen.com>
Roger Sayle <roger@eyesopen.com> writes:
| I still think that restricted folding is possible during parsing,
| provided that it's done carefully. For example, for the testcase
| attached to the PR, I believe that:
|
| template<int N> void foo()
| {
| double d = (N ? 0.0 : 0) + 1;
| }
|
| could be simplified to
|
| template<int N> void foo()
| {
| double d = 1.0;
| }
I believe that would be a mistake -- a stated desire I read from Mark
recently (and a dare desire/need for some of us) is to have g++
represent C++ programs at the most abstract faithful high-level. It is
something that is needed for program analysis and transformations, and
other competing C++ front-ends have learnt to avoid such aggressive
transformations during parsing.
Unlike the C standard, the C++ standards clearly states that if you
happen to have the above two function templates in the same program --
but each in different translation units, then your program is
ill-formed (no matter how functionally equivalent they are).
--
Gabriel Dos Reis
gdr@cs.tamu.edu
Texas A&M University -- Department of Computer Science
301, Bright Building -- College Station, TX 77843-3112