First Last Prev Next    No search results available      Search page      Enter new bug
Bug#: 11196
Product:  
Component:  
Status: NEW
Resolution:
Assigned To: Not yet assigned to anyone <unassigned@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: Tan Kheng-Chong <is88071@cis.nctu.edu.tw>
Add CC:
CC:
Remove selected CCs
Build:
URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 11196 depends on: Show dependency tree
Show dependency graph
Bug 11196 blocks:

Additional Comments:





Mark bug as waiting for feedback
Mark bug as suspended




View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: 2005-12-31 03:19 Opened: 2003-06-15 17:24
preprocessor error!

I wrote a simple C++ programing using GCC 3.2-cygwin, MingW, Linux, etc version
as below.
===================
#include<iostream>
using namespace std;

const double M_PI = 3.1415;

int main()
{
    cout << M_PI << endl;
    return 0;
}
===================

There're a parsing error in "M_PI". It has been defined in cmath(math.h) as:
#define M_PI 3.14159265358979323846

But, I didn't include the <cmath> header file. After undefined the M_PI, no
error be found. I think it's an error of preprocessor of GCC. 

For addition, I just included <iostream> header file, I can use all of methods
declared in <cmath> header file. It's no compiling error on 2.95 or older
version of GCC.

------- Comment #1 From Gabriel Dos Reis 2003-06-15 17:29 -------
Subject: Re:  New: parse error before numeric constant

"is88071@cis.nctu.edu.tw" <gcc-bugzilla@gcc.gnu.org> writes:


| I wrote a simple C++ programing using GCC 3.2-cygwin, MingW, Linux, etc version
| as below.
| ===================
| #include<iostream>
| using namespace std;
| 
| const double M_PI = 3.1415;
| 
| int main()
| {
|     cout << M_PI << endl;
|     return 0;
| }
| ===================
| 
| There're a parsing error in "M_PI". It has been defined in cmath(math.h) as:
| #define M_PI 3.14159265358979323846
| 
| But, I didn't include the <cmath> header file.

Agreed.  However, <iostream> is permitted to include <cmath>.  But
<cmath> is not supposed to define M_PI, that we fail to provide a
clean <cmath> is a bug in libstdc++.  However what the right fix
should be is not obvious.

-- Gaby

------- Comment #2 From Andrew Pinski 2003-06-15 17:36 -------
This is not a bug as the ISO C++ standard say that any standard header can
include any other 
standard headers so you include iostream which in turns includes cmath.h. The
bug is that 
cmath.h should not define M_PI which is not included in the C++ standard but is
included in 
XOPEN/SVID.

------- Comment #3 From Gabriel Dos Reis 2003-06-15 17:52 -------
Subject: Re:  parse error before numeric constant

"pinskia@physics.uc.edu" <gcc-bugzilla@gcc.gnu.org> writes:

| This is not a bug as the ISO C++ standard say that any standard header can include any other 
| standard headers so you include iostream which in turns includes cmath.h. The bug is that 
| cmath.h should not define M_PI which is not included in the C++ standard but is included in 
| XOPEN/SVID.

That is untrue.  XOPEN/SVID does not say <cmath> should define M_PI.
The issue isn't not that simple.  We should just resolve this as of
being very low priority bug to fix. 

-- Gaby

------- Comment #4 From Wolfgang Bangerth 2003-06-16 14:25 -------
Downgrade priorities. This code is just so unnecessary that it can't be
important
to fix it. Also change category to libstdc++.
W.

------- Comment #5 From Andrew Pinski 2003-06-18 17:08 -------
This is a bug, see mine and gdr's anyalsis.

------- Comment #6 From Jan van Dijk 2004-03-08 12:20 -------
The bug is that the C++ front end implicitly #defines _GNU_SOURCE. 
 
In glibc (I have version 2.3.2 here) this, amongst others, enables _BSD_SOURCE 
(see /usr/include/features.h). That in turn enables non-standard symbols like 
M_PI in math.h. Hence the failure. 
 
As a result one can argue that this is a C++ front end bug... however:   
 
gcc/config/linux.h tells us that: 
 
/* The GNU C++ standard library requires that these macros be defined.  */ 
#undef CPLUSPLUS_CPP_SPEC 
#define CPLUSPLUS_CPP_SPEC "-D_GNU_SOURCE %(cpp)" 
 
... so this may be a libstdc++ issue after all.  
 
The #define is also present for other configuration files in gcc/config/* and 
subdirectories. 
 
I googled and searched the libstdc++ archives and Changelog files, but did no 
find the reason why _GNU_SOURCE is in fact needed by gnu's libstdc++. I just 
removed the -D_GNU_SOURCE from gcc/config/linux.h (on i686-suse-linux) and 
bootstrapped gcc (HEAD) with languages=c,c++. That went just fine and 
(obviously) fixed the problem reported here. 
 
Could some libstdc++ guru explain why this define is actually needed? 

------- Comment #7 From Eelis 2007-11-13 18:42 -------
(In reply to comment #6)
> The bug is that the C++ front end implicitly #defines _GNU_SOURCE. 
> [..]
> Could some libstdc++ guru explain why this define is actually needed? 

I am no libstdc++ guru, but this:

  echo "#include <cstdlib>" | g++ -x c++ -U _GNU_SOURCE -c -

produces:

  /usr/include/c++/4.1.2/cstdlib:162: error: ‘::lldiv_t’ has not been
declared
  /usr/include/c++/4.1.2/cstdlib:168: error: ‘::_Exit’ has not been
declared
  /usr/include/c++/4.1.2/cstdlib:175: error: ‘::llabs’ has not been
declared
  /usr/include/c++/4.1.2/cstdlib:177: error: ‘lldiv_t’ does not name a type
  /usr/include/c++/4.1.2/cstdlib:181: error: ‘::lldiv’ has not been
declared
  /usr/include/c++/4.1.2/cstdlib:196: error: ‘::strtof’ has not been
declared
  /usr/include/c++/4.1.2/cstdlib:197: error: ‘::strtold’ has not been
declared
  /usr/include/c++/4.1.2/cstdlib:203: error: ‘__gnu_cxx::lldiv_t’ has not
been declared
  /usr/include/c++/4.1.2/cstdlib:205: error: ‘__gnu_cxx::_Exit’ has not
been declared
  /usr/include/c++/4.1.2/cstdlib:208: error: ‘__gnu_cxx::llabs’ has not
been declared
  /usr/include/c++/4.1.2/cstdlib:209: error: ‘__gnu_cxx::div’ has not been
declared
  /usr/include/c++/4.1.2/cstdlib:210: error: ‘__gnu_cxx::lldiv’ has not
been declared
  /usr/include/c++/4.1.2/cstdlib:213: error: ‘__gnu_cxx::strtof’ has not
been declared
  /usr/include/c++/4.1.2/cstdlib:216: error: ‘__gnu_cxx::strtold’ has not
been declared

------- Comment #8 From Paolo Carlini 2008-03-12 19:47 -------
*** Bug 35557 has been marked as a duplicate of this bug. ***

------- Comment #9 From Benjamin Kosnik 2009-01-27 00:26 -------
Update summary.

First Last Prev Next    No search results available      Search page      Enter new bug