g++: Default construction surrounded by parens doesn't parse right.

Robert Kennedy rkennedy@bigbird.engr.sgi.com
Thu Jan 28 12:25:00 GMT 1999


The example program quoted below is valid C++, but is rejected by
egcs-1.1.1. It would be great if you could send me a patch to fix this
problem ASAP.

	-- Robert Kennedy

gimme> g++ -v
Reading specs from /usr/local/lib/gcc-lib/i586-pc-linux-gnu/egcs-2.91.60/specs
gcc version egcs-2.91.60 19981201 (egcs-1.1.1 release)
gimme> cat test3.C
#include <stdio.h>

enum selector {
  off = 0,
  on  = 1
};

template <class pointer_type>
struct base_template_class
{
};

template <selector s, class pointer_type = int *>
struct template_class : public base_template_class<pointer_type>
{
};

template <class pointer_type>
struct template_class<off, pointer_type> :
  public base_template_class<pointer_type>
{
  template_class(pointer_type p) { printf("Constructing an 'off'\n"); }
  template_class(void) { printf("Default constructing an 'off'\n"); }
};

template <class pointer_type>
struct template_class<on, pointer_type> :
  public base_template_class<pointer_type>
{
  template_class(pointer_type p) { printf("Constructing an 'on'\n"); }
  template_class(void) { printf("Default constructing an 'on'\n"); }
};

template <class pointer_type>
bool operator==(const base_template_class<pointer_type> &x,
                const base_template_class<pointer_type> &y)
{
  return 1;
}

template <class pointer_type>
bool operator!=(const base_template_class<pointer_type> &x,
                const base_template_class<pointer_type> &y)
{
  return !(x == y);
}

int main(void)
{
  int q;
  int *p = &q;
  template_class<off> x(p);
  while(x != template_class<off, int *>()) {
    printf("loop1\n");
  }
  // The preceding loop compiles without errors, as it should. The
  // following loop gets a parse error, even though it is valid. The
  // only difference is a single layer of correctly nested parentheses.
  while(x != (template_class<off, int *>())) {
    printf("loop2\n");
  }
  printf("done\n");
}
gimme> g++ -c test3.C
test3.C: In function `int main()':
test3.C:59: parse error before `)'
test3.C:61: confused by earlier errors, bailing out
gimme>



More information about the Gcc-bugs mailing list