Ignore:
Timestamp:
Sep 9, 2016, 9:20:33 AM (5 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
b6fe7e6
Parents:
4563a95
Message:

check that assignment routines have a reasonable signature, add noreturn attribute to assert_fail_f to silence warnings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r4563a95 rd1969a6  
    6060#include "ResolvExpr/typeops.h"
    6161#include <algorithm>
     62#include "InitTweak/InitTweak.h"
    6263
    6364#define debugPrint( x ) if ( doDebug ) { std::cout << x; }
     
    171172        };
    172173
    173         class VerifyCtorDtor : public Visitor {
     174        class VerifyCtorDtorAssign : public Visitor {
    174175        public:
    175                 /// ensure that constructors and destructors have at least one
    176                 /// parameter, the first of which must be a pointer, and no
     176                /// ensure that constructors, destructors, and assignment have at least one
     177                /// parameter, the first of which must be a pointer, and that ctor/dtors have no
    177178                /// return values.
    178179                static void verify( std::list< Declaration * > &translationUnit );
     
    202203                compoundliteral.mutateDeclarationList( translationUnit );
    203204                acceptAll( translationUnit, pass3 );
    204                 VerifyCtorDtor::verify( translationUnit );
     205                VerifyCtorDtorAssign::verify( translationUnit );
    205206        }
    206207
     
    687688        }
    688689
    689         void VerifyCtorDtor::verify( std::list< Declaration * > & translationUnit ) {
    690                 VerifyCtorDtor verifier;
     690        void VerifyCtorDtorAssign::verify( std::list< Declaration * > & translationUnit ) {
     691                VerifyCtorDtorAssign verifier;
    691692                acceptAll( translationUnit, verifier );
    692693        }
    693694
    694         void VerifyCtorDtor::visit( FunctionDecl * funcDecl ) {
     695        void VerifyCtorDtorAssign::visit( FunctionDecl * funcDecl ) {
    695696                FunctionType * funcType = funcDecl->get_functionType();
    696697                std::list< DeclarationWithType * > &returnVals = funcType->get_returnVals();
    697698                std::list< DeclarationWithType * > &params = funcType->get_parameters();
    698699
    699                 if ( funcDecl->get_name() == "?{}" || funcDecl->get_name() == "^?{}" ) {
     700                if ( InitTweak::isCtorDtorAssign( funcDecl->get_name() ) ) {
    700701                        if ( params.size() == 0 ) {
    701                                 throw SemanticError( "Constructors and destructors require at least one parameter ", funcDecl );
     702                                throw SemanticError( "Constructors, destructors, and assignment functions require at least one parameter ", funcDecl );
    702703                        }
    703704                        if ( ! dynamic_cast< PointerType * >( params.front()->get_type() ) ) {
    704                                 throw SemanticError( "First parameter of a constructor or destructor must be a pointer ", funcDecl );
     705                                throw SemanticError( "First parameter of a constructor, destructor, or assignment function must be a pointer ", funcDecl );
    705706                        }
    706                         if ( returnVals.size() != 0 ) {
     707                        if ( InitTweak::isCtorDtor( funcDecl->get_name() ) && returnVals.size() != 0 ) {
    707708                                throw SemanticError( "Constructors and destructors cannot have explicit return values ", funcDecl );
    708709                        }
Note: See TracChangeset for help on using the changeset viewer.