Changeset 790f251


Ignore:
Timestamp:
Aug 22, 2024, 2:32:14 PM (4 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
cc0aa8c
Parents:
df2e00f
Message:

update error message for parameter default-initialization in function-pointer declarations

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cpp

    rdf2e00f r790f251  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Feb 23 18:25:57 2024
    13 // Update Count     : 1533
     12// Last Modified On : Thu Aug 22 14:11:47 2024
     13// Update Count     : 1555
    1414//
    1515
     
    134134                os << endl << string( indent + 2, ' ' ) << "with initializer ";
    135135                initializer->printOneLine( os );
    136                 os << " maybe constructed? " << initializer->get_maybeConstructed();
     136                if ( ! initializer->get_maybeConstructed() ) {
     137                        os << " constructed with @= ";
     138                } // if
    137139        } // if
    138140
     
    9991001        assert( type );
    10001002
    1001         // Some types are parsed as declarations and, syntactically, can have
    1002         // initializers. However, semantically, this is meaningless.
    1003         if ( initializer ) {
    1004                 SemanticError( this, "Initializer on type declaration " );
     1003        // Some types are parsed as declarations and, syntactically, can have initializers, which are not support (possibly
     1004        // meaningless).
     1005        if ( initializer && initializer->get_maybeConstructed() ) { // no @=
     1006                SemanticError( location, "default initialization for parameter %s is unsupport for a function-pointer declaration.",
     1007                                           (this->name) ? this->name->c_str() : "anonymous" );
    10051008        }
    10061009
  • tests/.expect/opt-params.txt

    rdf2e00f r790f251  
    1 opt-params.cfa:12:1 error: Initializer on type declaration i: int
    2   with initializer  maybe constructed? 1
    3 
    4 opt-params.cfa:13:1 error: Initializer on type declaration int
    5   with initializer  maybe constructed? 1
    6 
    7 opt-params.cfa:14:1 error: Initializer on type declaration int
    8   with initializer  maybe constructed? 1
    9 
    10 opt-params.cfa:15:1 error: Initializer on type declaration int
    11   with initializer  maybe constructed? 1
    12 
     1opt-params.cfa:13:1 error: default initialization for parameter i is unsupport for a function-pointer declaration.
     2opt-params.cfa:13:1 error: default initialization for parameter j is unsupport for a function-pointer declaration.
     3opt-params.cfa:14:1 error: default initialization for parameter anonymous is unsupport for a function-pointer declaration.
     4opt-params.cfa:15:1 error: default initialization for parameter anonymous is unsupport for a function-pointer declaration.
     5opt-params.cfa:16:1 error: default initialization for parameter anonymous is unsupport for a function-pointer declaration.
     6opt-params.cfa:17:1 error: default initialization for parameter i is unsupport for a function-pointer declaration.
     7opt-params.cfa:18:1 error: default initialization for parameter i is unsupport for a function-pointer declaration.
  • tests/opt-params.cfa

    rdf2e00f r790f251  
    99// This is a slightly weird way to do it, but it let's us try all the cases
    1010// before any of the errors cause compilation to stop.
     11
    1112void bad_cases(
    12         int (*fee)( int i = 10 ),
    13         int (*fie)( int = 10 ),
    14         void feo( int (*p)( int = 10 ) ),
    15         void fum( int (*)( int = 10 ) )
     13        int (*f1)( int i = 10, int j = 5 ),
     14        int (*f2)( int = 10 ),
     15        void f3( int (*p)( int = 10 ) ),
     16        void f4( int (*)( int = 10 ) ),
     17        void f5( int (*p)( int i = 10 ) ),
     18        void f6( int (*)( int i = 10 ) )
    1619);
     20
Note: See TracChangeset for help on using the changeset viewer.