This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [3.4 PATCH] PR c++/20995: Type-unsafe trees for templates


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]