Boost logo

Boost :

From: Jens Maurer (jmaurer_at_[hidden])
Date: 2000-04-27 17:03:58


I've put up some problems with Borland C++ v5.5 at
http://www.rhein-main.de/people/jmaurer/borland_cpp.html

I suggest collecting information like this in the "more" section
of boost.

For your convenience, here is an ASCII rendering of the text:

Dealing with Borland C++ 5.5

Nearly all C++ compilers leave something to be desired in terms of ISO C++
conformance. While boost libraries aim for standards compliant compilers,
they should also work with popular, but possibly not quite compliant,
compilers to be useful and thus to become used.

This document describes how to deal with the shortcomings of the Win32
command-line compiler Borland C++ v5.5, which is freely available at
http://www.borland.com/.

The preprocessor symbol __BORLANDC__ is defined for the Borland C++
compiler. Its value is the version number of the compiler in hex, for example
0x0550 for v5.5.

Core Language

[using-directive] Mixing using-declarations and
using-directives

Mixing using-directives (which refer to whole namespaces) and
namespace-level using-declarations (which refer to individual identifiers
within foreign namespaces) causes ambiguities where there are none. The
following code fragment illustrates this:

namespace N {
  int x();
}

using N::x;
using namespace N;

int main()
{
  &x; // Ambiguous overload
}

See [except.h] for a case where this matters in case of namespace std.

[using-template] using-declarations for class templates

Identifiers for class templates can be used as arguments to
using-declarations as any other identifier. However, the following code
fails to compile with Borland C++:

template<class T>
class X { };

namespace N
{
  // "cannot use template 'X' without specifying specialization parameters"
  using ::X;
};

This bites if you define BOOST_NO_OPERATIONS_IN_NAMESPACE,
whence such using-declarations are then employed in
boost/operators.hpp.

[inline friend] Inline friend functions in template classes

If a friend function of some class has not been declared before the friend
function declaration, the function is declared at the namespace scope
surrounding the class definition. Together with class templates and inline
definitions of friend functions, the code in the following fragment should
declare (and define) a non-template function "bool N::f(int,int)", which is a
friend of class N::A<int>. However, Borland C++ v5.5 expects the function f
to be declared beforehand:

namespace N {
template<class T>
class A
{
  // "f is not a member of 'N' in function main()"
  friend bool f(T x, T y) { return x < y; }
};
}

int main()
{
  N::A<int> a;
}

This technique is extensively used in boost/operators.hpp. Giving in to the
wish of the compiler doesn't work in this case, because the the "instantiate
one template, get lots of helper functions at namespace scope" approach
doesn't work anymore. Defining
BOOST_NO_OPERATORS_IN_NAMESPACE (a define
BOOST_NO_INLINE_FRIENDS_IN_CLASS_TEMPLATES would be
better) works around this problem and leads to the next one, see
[using-template].

[template const arg] Deduction of constant arguments to
function templates

Template function type deduction should omit top-level constness. However,
this code fragment instantiates "f<const int>(int)":

template<class T>
void f(T x)
{
        x = 1; // works
        (void) &x;
        T y = 17;
        y = 20; // "Cannot modify a const object in function f(int)"
        (void) &y;
}

int main()
{
        const int i = 17;
        f(i);
}

This bites in boost/rational.hpp with the gcd function.

Library

The library is Rogue Wave based.

[except.h] Incorrect except.h

The header file except.h includes <stdlib.h>, but it should include
<cstdlib> instead in order to avoid polluting the global namespace.
Together with problem [using-directive] and the fact that <algorithm>
includes except.h indirectly, this means that
boost/libs/compose/compose3.cpp will not compile.

Workaround: Do not say "using namespace std" in your code, use explicit
qualifications with std:: instead.

Jens Maurer.


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