Boost logo

Boost :

From: John Maddock (John_Maddock_at_[hidden])
Date: 2000-10-15 06:25:35


Hi,

I've had a VC6 related bug report for the regex library which relates to
the way in which config.hpp defines min and max. As a result the following
program crahes and burns inside config.hpp when built on VC6:

/*
        Copyright (c) 2000, Escher Group Ltd., Cambridge, Massachusetts
        All rights reserved.
*/

//#include "cstd.h"
#include <stdlib.h>
#include <windows.h>

/* regexpr++ support for posix regular expressions */
#include "boost/regex.h"

//#include "cdbg.h"

/*
   Reference:
   http://www.boost.org/libs/regex/index.htm
   http://www.opengroup.org/onlinepubs/007908799/xsh/regcomp.html
*/

/*
   Match string against the extended regular expression in
   pattern, treating errors as no match.
 
   return 1 for match, 0 for no match
*/

extern "C"
int xpathRegExprMatch(const char *string, char *pattern)
{
    int status;
    regex_t re;

    /* REG_EXTENDED Use Extended Regular Expressions. */
    /* REG_NOSUB Report only success/fail in regexec(). */
    if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB ) != 0) return FALSE;
    /* report error */

    status = regexec(&re, string, (size_t) 0, 0, 0);
    regfree(&re);

    if (status != FALSE) return FALSE; /* report error */
    return TRUE;
}

Here are the error messages:

msvc_win.cpp
../../../../boost/config.hpp(371) : error C2226: syntax error : unexpected
type '_Tp'
../../../../boost/config.hpp(371) : error C2062: type 'const int'
unexpected
../../../../boost/config.hpp(371) : error C2059: syntax error : ')'
../../../../boost/config.hpp(375) : error C2062: type 'const int'
unexpected
../../../../boost/config.hpp(375) : error C2059: syntax error : ')'
../../../../boost/config.hpp(375) : error C2143: syntax error : missing ';'
before '{'
../../../../boost/config.hpp(375) : error C2447: missing function header
(old-style formal list?)
e:\VS98\INCLUDE\memory(15) : error C2954: template definitions cannot nest
../../../../boost/re_detail/regex_config.hpp(918) : fatal error C1506:
unrecoverable block scoping error

The problem is the section just added by Jeremy:

#ifdef BOOST_NO_STD_MIN_MAX
namespace std {
  template <class _Tp>
  inline const _Tp& min(const _Tp& __a, const _Tp& __b) {
    return __b < __a ? __b : __a;
  }
  template <class _Tp>
  inline const _Tp& max(const _Tp& __a, const _Tp& __b) {
    return __a < __b ? __b : __a;
  }
}
#endif

which will crash and burn if min/max are already defined as macros.

Suggestions?

- John.


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