Ignore:
Timestamp:
Jun 13, 2023, 4:33:16 PM (12 months ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master
Children:
5668740, fec8bd1
Parents:
576aadb
Message:

Clarify and fix accuracy in eval public API, on reporting "unable to evaluate."

While the eval internals always used the flag pair valid and cfavalid almost correctly, the public interface exposed the outcome as a single flag, and the various interpretations of this flag were a mess.

Old cfacc treated sizeof(whatever) in some contexts as "known to be zero," which is wrong.
The generally correct answer, which new cfacc now uses is, "unknown now, but GCC will see it as a fine constant."
New tests/eval.cfa captures this fact: is runnable and would fail on old cfacc; it passes with new cfacc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CurrentObject.cc

    r576aadb r8f557161  
    689689
    690690                        auto arg = eval( expr );
    691                         index = arg.first;
     691                        assertf( arg.hasKnownValue, "Non-evaluable expression made it to IndexIterator" );
     692                        index = arg.knownValue;
    692693
    693694                        // if ( auto constExpr = dynamic_cast< const ConstantExpr * >( expr ) ) {
     
    728729                size_t getSize( const Expr * expr ) {
    729730                        auto res = eval( expr );
    730                         if ( !res.second ) {
     731                        if ( !res.hasKnownValue ) {
    731732                                SemanticError( location, toString( "Array designator must be a constant expression: ", expr ) );
    732733                        }
    733                         return res.first;
     734                        return res.knownValue;
    734735                }
    735736
Note: See TracChangeset for help on using the changeset viewer.