Boost logo

Boost :

From: Boris Gubenko (Boris.Gubenko_at_[hidden])
Date: 2007-09-20 09:44:25


Markus Schoepflin wrote:
> Both my compiler (Tru64 CXX 7.1) and Comeau C++ Online think this code is
> in error:

You see the error because you compile in strict ansi mode which enables
"strict dependent name lookup rules to be used in templates". It is the
same with all EDG-based compilers:

cxxosf.zko.hp.com> eccp -c --no_dep_name --version m.cpp
Edison Design Group C/C++ Front End, version 3.5 (Dec 20 2004 13:57:48)
Copyright 1988-2004 Edison Design Group, Inc.

cxxosf.zko.hp.com> eccp -c --dep_name --version m.cpp
Edison Design Group C/C++ Front End, version 3.5 (Dec 20 2004 13:57:48)
Copyright 1988-2004 Edison Design Group, Inc.

"m.cpp", line 4: error: identifier "make_foo" is undefined
     template <class T> foo(T t) { *this = make_foo(t); }
                                           ^
          detected during instantiation of "foo::foo(T) [with T=int]" at line 9

1 error detected in the compilation of "m.cpp".
cxxosf.zko.hp.com>

> Therefore I think this should be changed to the following:

Another way of fixing it, the one that does not involve explicit
specialization, can be defining foo's template ctor after make_foo()
has been defined (or declared):

---%<---
struct foo
{
   foo() {}
   template <class T> foo(T);
};

inline foo make_foo(int i) { return foo(); }

template <class T> foo::foo(T t) { *this = make_foo(t); }

foo f(42);
--->%---

Thanks,
  Boris

----- Original Message -----
From: "Markus Schöpflin" <markus.schoepflin_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, September 20, 2007 5:52 AM
Subject: [boost] [system] Possible error in error_code.hpp

> Hello,
>
> this file contains code to create an error condition, which basically looks
> like this:
>
> ---%<---
> struct foo
> {
> foo() {}
> template <class T> foo(T t) { *this = make_foo(t); }
> };
>
> inline foo make_foo(int i) { return foo(); }
>
> foo f(42);
> --->%---
>
> Both my compiler (Tru64 CXX 7.1) and Comeau C++ Online think this code is
> in error:
>
> ---%<---
> cxx: Error: test.cxx, line 4: identifier "make_foo" is undefined
> detected during instantiation of "foo::foo(T) [with T=int]" at
> line 9
> template <class T> foo(T t) { *this = make_foo(t); }
> ----------------------------------------^
> --->%---
>
> Therefore I think this should be changed to the following:
>
> ---%<---
> struct foo;
> template <class T> foo make_foo(T);
>
> struct foo
> {
> foo() {}
> template <class T> foo(T t) { *this = make_foo(t); }
> };
>
> template<> foo make_foo(int i) { return foo(); }
>
> foo f(42);
> --->%---
>
> Is this correct? If yes, could that header be fixed?
>
>
> TIA, Markus
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk