public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/14789] New: Preprocessor broken
@ 2004-03-30 23:43 s_gccbugzilla at nedprod dot com
  2004-03-30 23:47 ` [Bug c++/14789] " pinskia at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: s_gccbugzilla at nedprod dot com @ 2004-03-30 23:43 UTC (permalink / raw)
  To: gcc-bugs

A very interesting bug this - I have found it in both v3.2.2 and v3.4 CVS 
20040324:

Test source:
/* Test for GCC v3.4 preprocessor bug
by Niall Douglas
*/

class FXApp;
template<class type> class iterator_range;

#define DEFINE_MAKECARRAYITER(contType, memberType, getArrayFunction, 
getArrayFunctionPars, getArrayLengthFunction) \
	static iterator_range<memberType *> 
##contType##_##getArrayFunction##(contType &c)

DEFINE_MAKECARRAYITER(FXApp, const char *, getArgv, (), c.getArgc())

int main(void)
{
}

Trying to compile this valid code causes an error. Listing CVS output:

[ned@katey Python]$ g++ -c -E preprocbug.cpp
# 1 "preprocbug.cpp"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "preprocbug.cpp"




class FXApp;
template<class type> class iterator_range;




preprocbug.cpp:11:1: pasting ">" and "FXApp" does not give a valid preprocessing 
token
preprocbug.cpp:11:1: pasting "FXApp_getArgv" and "(" does not give a valid 
preprocessing token
static iterator_range<const char * *>FXApp_getArgv(FXApp &c)

int main(void)
{
}
[ned@katey Python]$ gcc --version
gcc (GCC) 3.4.0 20040324 (prerelease)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

As you can see, it's forgetting to put a space in before the token insert. I'd 
imagine this is a very easy bug to fix for someone familiar with the code

Cheers,
Niall

-- 
           Summary: Preprocessor broken
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: s_gccbugzilla at nedprod dot com
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14789


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/14789] Preprocessor broken
  2004-03-30 23:43 [Bug c++/14789] New: Preprocessor broken s_gccbugzilla at nedprod dot com
@ 2004-03-30 23:47 ` pinskia at gcc dot gnu dot org
  2004-03-31  0:00 ` [Bug preprocessor/14789] " zack at codesourcery dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-03-30 23:47 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-03-30 23:47 -------
Read the error message, it is right.
You cannot paste together > and a name to give a token.
Instead of ">##contType" use "> contType"

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14789


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug preprocessor/14789] Preprocessor broken
  2004-03-30 23:43 [Bug c++/14789] New: Preprocessor broken s_gccbugzilla at nedprod dot com
  2004-03-30 23:47 ` [Bug c++/14789] " pinskia at gcc dot gnu dot org
@ 2004-03-31  0:00 ` zack at codesourcery dot com
  2004-03-31  0:10 ` s_gccbugzilla at nedprod dot com
  2004-03-31  9:49 ` zack at codesourcery dot com
  3 siblings, 0 replies; 5+ messages in thread
From: zack at codesourcery dot com @ 2004-03-31  0:00 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From zack at codesourcery dot com  2004-03-31 00:00 -------
Subject: Re:  New: Preprocessor broken

"s_gccbugzilla at nedprod dot com" <gcc-bugzilla@gcc.gnu.org> writes:

> #define DEFINE_MAKECARRAYITER(contType, memberType, getArrayFunction, 
> getArrayFunctionPars, getArrayLengthFunction) \
> 	static iterator_range<memberType *> 
> ##contType##_##getArrayFunction##(contType &c)

I'm going to assume that the word wrap between lines 1 and 2, 3 and 4
of this was unintentional.

> preprocbug.cpp:11:1: pasting ">" and "FXApp" does not give a valid preprocessing 
> token
> preprocbug.cpp:11:1: pasting "FXApp_getArgv" and "(" does not give a valid 
> preprocessing token

These are hard errors for a reason.  They indicate bugs in your code.
A corrected version (with the unused arguments dropped for
readability) would be something like this:

#define DEFINE_MAKECARRAYITER(contType, memberType, getArrayFunction) \
  static iterator_range<memberType *> contType##_##getArrayFunction \
    (contType &c)

i.e. all you have to do is remove two incorrect and unnecessary ##
operators.

zw


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14789


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug preprocessor/14789] Preprocessor broken
  2004-03-30 23:43 [Bug c++/14789] New: Preprocessor broken s_gccbugzilla at nedprod dot com
  2004-03-30 23:47 ` [Bug c++/14789] " pinskia at gcc dot gnu dot org
  2004-03-31  0:00 ` [Bug preprocessor/14789] " zack at codesourcery dot com
@ 2004-03-31  0:10 ` s_gccbugzilla at nedprod dot com
  2004-03-31  9:49 ` zack at codesourcery dot com
  3 siblings, 0 replies; 5+ messages in thread
From: s_gccbugzilla at nedprod dot com @ 2004-03-31  0:10 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From s_gccbugzilla at nedprod dot com  2004-03-31 00:10 -------
Ach, when I look at it now you're completely right. It's late and I'm not seeing 
straight, plus MSVC compiled it fine. The bug is in MSVC (and probably EDG) 
then.

Sorry about wasting your time.

Cheers,
Niall


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14789


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug preprocessor/14789] Preprocessor broken
  2004-03-30 23:43 [Bug c++/14789] New: Preprocessor broken s_gccbugzilla at nedprod dot com
                   ` (2 preceding siblings ...)
  2004-03-31  0:10 ` s_gccbugzilla at nedprod dot com
@ 2004-03-31  9:49 ` zack at codesourcery dot com
  3 siblings, 0 replies; 5+ messages in thread
From: zack at codesourcery dot com @ 2004-03-31  9:49 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From zack at codesourcery dot com  2004-03-31 09:49 -------
Subject: Re:  Preprocessor broken


Not so much a bug in those compilers as that they're just not as picky
as GCC.  This is an instance of what the C standard calls "compile-
time undefined behavior" which means a compiler is not obliged to
issue an error on this code -- but it isn't obliged to do anything
sensible or helpful either.

zw


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14789


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-03-31  9:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-30 23:43 [Bug c++/14789] New: Preprocessor broken s_gccbugzilla at nedprod dot com
2004-03-30 23:47 ` [Bug c++/14789] " pinskia at gcc dot gnu dot org
2004-03-31  0:00 ` [Bug preprocessor/14789] " zack at codesourcery dot com
2004-03-31  0:10 ` s_gccbugzilla at nedprod dot com
2004-03-31  9:49 ` zack at codesourcery dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).