Changeset d1969a6


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

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/InitTweak.cc

    r4563a95 rd1969a6  
    358358                template<typename CallExpr>
    359359                Expression *& callArg( CallExpr * callExpr, unsigned int pos ) {
    360                         if ( pos >= callExpr->get_args().size() ) assert( false && "asking for argument that doesn't exist. Return NULL/throw exception?" );
     360                        if ( pos >= callExpr->get_args().size() ) assertf( false, "asking for argument that doesn't exist. Return NULL/throw exception?" );
    361361                        for ( Expression *& arg : callExpr->get_args() ) {
    362362                                if ( pos == 0 ) return arg;
     
    373373                        return callArg( untypedExpr, pos );
    374374                } else {
    375                         assert( false && "Unexpected expression type passed to getCallArg" );
     375                        assertf( false, "Unexpected expression type passed to getCallArg" );
    376376                }
    377377        }
     
    388388                                return memberExpr->get_member()->get_name();
    389389                        } else {
    390                                 assert( false && "Unexpected expression type being called as a function in call expression" );
     390                                assertf( false, "Unexpected expression type being called as a function in call expression" );
    391391                        }
    392392                }
     
    400400                } else {
    401401                        std::cerr << expr << std::endl;
    402                         assert( false && "Unexpected expression type passed to getFunctionName" );
     402                        assertf( false, "Unexpected expression type passed to getFunctionName" );
    403403                }
    404404        }
  • 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                        }
  • src/include/assert.h

    r4563a95 rd1969a6  
    2222#define assertf(expr, fmt, ...) ((expr) ? static_cast<void>(0) : __assert_fail_f(__VSTRINGIFY__(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, ## __VA_ARGS__ ))
    2323
    24 void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... );
     24void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... ) __attribute__((noreturn));
    2525
    2626template<typename T, typename U>
Note: See TracChangeset for help on using the changeset viewer.