Opened 5 years ago

Closed 2 years ago

#142 closed defect (fixed)

constant expression problem

Reported by: pabuhr Owned by:
Priority: major Component: cfa-cc
Version: 1.0 Keywords:
Cc:

Description

The following works with gcc but fails with CFA.

struct S {
    int i;
};
enum { X = sizeof(struct S) };
int x[X];

cfa test5.cfa
CFA Version 1.0.0 (debug)
test5.cfa:4:1 error: Non-constexpr in initialization of enumerator: X: const instance of enum __anonymous0 with body 1 with initializer (not constructed)
  Simple Initializer: Generated Cast of:
    Sizeof Expression on: instance of struct S with body 1
  ... to:
    signed int
  ... with environment:
    Types:
    Non-types:

Change History (2)

comment:1 Changed 5 years ago by Rob Schluntz

This might be an easy fix. I would trace through ConstExprChecker and see what it's doing with this expression. Reading the code, I would have thought it would work, but maybe there's a hidden TypeExpr here? Apparently TypeExpr doesn't print any extra prefix (see TypeExpr::print), it might be worth adding one there to prevent confusion in the future.

comment:2 Changed 2 years ago by Thierry Delisle

Resolution: fixed
Status: newclosed

This code now compiles.

Note: See TracTickets for help on using tickets.