Opened 9 years ago

Closed 9 years ago

#437 closed bug (fixed)

negate() should be NTL::negate()

Reported by: jdemeyer@… Owned by: somebody
Priority: major Milestone: 3-1-5 and higher
Component: factory Version:
Keywords: g++ ntl negate Cc:

Description

In factory/cf_chinese.cc, the NTL function negate() is called twice. However, due to a conflict between NTL::negate() and std::negate(), compilation fails:

g++ -c cf_chinese.cc -Wall -fno-implicit-templates -I. -I.. -I. -I/release/merger/sage-5.2.rc1/local -I/release/merger/sage-5.2.rc1/local/
include -DHAVE_CONFIG_H -I/release/merger/sage-5.2.rc1/local/include -I/release/merger/sage-5.2.rc1/local/include -I/release/merger/sage-5
.2.rc1/local/include  -O2 -g -fPIC  -o cf_chinese.o
cf_chinese.cc: In function 'CanonicalForm Farey(const CanonicalForm&, const CanonicalForm&)':
cf_chinese.cc:214: error: reference to 'negate' is ambiguous
/release/merger/sage-5.2.rc1/local/include/NTL/mat_lzz_pE.h:17: error: candidates are: void NTL::negate(NTL::mat_zz_pE&, const NTL::mat_zz
_pE&)
[...lots more...]
/release/merger/sage-5.2.rc1/local/include/NTL/vec_ZZ.h:28: error: candidates are: void NTL::negate(NTL::vec_ZZ&, const NTL::vec_ZZ&)
/release/merger/sage-5.2.rc1/local/include/NTL/ZZ.h:301: error: candidates are: void NTL::negate(NTL::ZZ&, const NTL::ZZ&)
/usr/include/c++/4.2/bits/stl_function.h:179: error:                 template<class _Tp> struct std::negate

Changing negate() to NTL::negate() fixes this. In Singular 3-1-4-4, this was correct but the NTL:: seems to have been removed in Singular 3-1-5.

Note: Version 3-1-5 isn't available in Trac.

Attachments (1)

NTL_negate.patch (857 bytes) - added by jdemeyer@… 9 years ago.
Fix

Download all attachments as: .zip

Change History (14)

Changed 9 years ago by jdemeyer@…

Attachment: NTL_negate.patch added

Fix

comment:1 Changed 9 years ago by hannes

NTL:: in front of the negate was removed, because with it it does not compile on Solaris.

comment:2 in reply to:  1 Changed 9 years ago by jdemeyer@…

Replying to hannes:

NTL:: in front of the negate was removed, because with it it does not compile on Solaris.

Really? I have compiled Singular-3-1-3-3 (as part of Sage) many times on Solaris and OpenSolaris (with several different versions of GCC) and never had any problem like this. I never tried SunCC, so maybe you're referring to that? Then the NTL:: could be conditionally added:

#ifdef __SUNPRO_CC
#define NTL_negate negate
#else
#define NTL_negate NTL::negate    
#endif
/*...*/
NTL_negate (NTLc, NTLc); 

comment:3 Changed 9 years ago by anonymous

No, the error occurs with gcc: g++ -c cf_chinese.cc -Wall -fno-implicit-templates -I. -I.. -I. -I/net/lummerland/users/cip/alggeom/hannes/galois32 -I/net/lummerland/users/cip/alggeom/hannes/galois32/SunOS-5/include -DHAVE_CONFIG_H -I/net/lummerland/users/cip/alggeom/hannes/galois32/SunOS-5/include -O2 -fomit-frame-pointer -fno-rtti -fno-exceptions -o cf_chinese.o cf_chinese.cc: In function `CanonicalForm? Farey(const CanonicalForm?&, const

CanonicalForm?&)':

cf_chinese.cc:223: error: `NTL' undeclared (first use this function) cf_chinese.cc:223: error: (Each undeclared identifier is reported only once for

each function it appears in.)

cf_chinese.cc:223: error: parse error before `::' token cf_chinese.cc:228: error: parse error before `::' token

Please check the patch www.singular.uni-kl.de:8002/trac/changeset/15131

#if defined(__STD_FUNCTIONAL__) || defined(_GLIBCXX_FUNCTIONAL) 
#define NTL_negate NTL::negate 
#else 
#define NTL_negate negate 
#endif 

comment:4 Changed 9 years ago by jdemeyer@…

Singular-3-1-5 even fails to build on Solaris 10 for me (#443), so I cannot really test.

comment:5 Changed 9 years ago by jdemeyer@…

The patch from comment 3 fails to build on Solaris 10 with GCC-4.6.3 and it fails to build on OpenSolaris 06.2009-32 with GCC-4.4.3. In both cases, NTL:: is required but not added by the patch. Singular-3-1-3-3 builds fine on these machines.

comment:6 in reply to:  5 Changed 9 years ago by dreyer

Replying to jdemeyer@…:

The patch from comment 3 fails to build on Solaris 10 with GCC-4.6.3 and it fails to build on OpenSolaris 06.2009-32 with GCC-4.4.3. In both cases, NTL:: is required but not added by the patch. Singular-3-1-3-3 builds fine on these machines.

Just to clarify: is the NTL_negate macro wrongly defined, i.e. negate instead of std::negate? Or are there additional places in the source where the macro should be placed?

comment:7 Changed 9 years ago by dreyer

I guess, that the macros __STD_FUNCTIONAL__ and _GLIBCXX_FUNCTIONAL depend on the implementation, so this might differ from gcc version to gcc. Since the compiler (suncc?) reports `NTL' undeclared, one should maybe check for this. It seems to the the actual source of the problem.

comment:8 Changed 9 years ago by jdemeyer@…

On OpenSolaris, I guess the "correct" macro is _STL_FUNCTION_H. But you probably shouldn't rely on that.

Which is the version of GCC which fails to build Singular with NTL::? Because on every system I tried, NTL::negate() works.

comment:9 Changed 9 years ago by hannes

NTL::negate yields an error with gcc version 3.3.2 and 3.4.2 on SunOS 5.9 sun4u sparc (`NTL' has not been declared)

comment:10 Changed 9 years ago by jdemeyer@…

Those are really ancient versions of GCC (2003 and 2004 respectively). I think it makes a lot more sense to support more recent versions of GCC.

comment:11 Changed 9 years ago by hannes

Surprising, because gcc 3.4 on another (non-sunos) machine accepts both variants. To solve this, what about the following patch:

#if !defined(__GNUC__) || (__GNUC__ > 3)
#define NTL_negate NTL::negate
#else
#define NTL_negate negate
#endif

comment:12 Changed 9 years ago by jdemeyer@…

That would work for me (but please add a comment mentioning this Trac ticket such that this doesn't get changed again in the future).

comment:13 Changed 9 years ago by hannes

Resolution: fixed
Status: newclosed

fixed by a test for gcc version <4

Note: See TracTickets for help on using tickets.