Changeset ecf3812 for src/GenPoly/Lvalue.cpp
- Timestamp:
- Nov 19, 2024, 5:02:03 PM (4 weeks ago)
- Branches:
- master
- Children:
- d945be9
- Parents:
- 29075d1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Lvalue.cpp
r29075d1 recf3812 315 315 SemanticWarning( expr->arg->location, 316 316 Warning::RvalueToReferenceConversion, toCString( expr->arg ) ); 317 318 317 319 318 // allowing conversion in the rvalue to const ref case … … 366 365 ret = new ast::AddressExpr( ret->location, ret ); 367 366 } 368 if ( expr->arg->get_lvalue() && 369 !ResolvExpr::typesCompatible( 370 srcType, 371 strict_dynamic_cast<ast::ReferenceType const *>( dstType )->base ) ) { 367 if ( !ResolvExpr::typesCompatible( 368 srcType, 369 strict_dynamic_cast<ast::ReferenceType const *>( dstType )->base ) ) { 372 370 // Must keep cast if cast-to type is different from the actual type. 373 371 return ast::mutate_field( expr, &ast::CastExpr::arg, ret ); … … 384 382 } 385 383 // Must keep cast if types are different. 386 if ( !ResolvExpr::typesCompatible IgnoreQualifiers(384 if ( !ResolvExpr::typesCompatible( 387 385 dstType->stripReferences(), 388 386 srcType->stripReferences() ) ) { … … 397 395 } else { 398 396 assert( 0 == diff ); 399 // Remove useless generated casts.400 if ( expr->isGenerated == ast::GeneratedFlag::GeneratedCast &&401 ResolvExpr::typesCompatible(397 // Must keep cast if types are different. (Or it is explicit.) 398 if ( ast::ExplicitCast == expr->isGenerated || 399 !ResolvExpr::typesCompatible( 402 400 expr->result, 403 401 expr->arg->result ) ) { 404 PRINT( 405 std::cerr << "types are compatible, removing cast: " << expr << '\n'; 406 std::cerr << "-- " << expr->result << '\n'; 407 std::cerr << "-- " << expr->arg->result << std::endl; 408 ) 409 auto argAsEnum = expr->arg.as<ast::EnumInstType>(); 410 auto resultAsEnum = expr->result.as<ast::EnumInstType>(); 411 if (argAsEnum && resultAsEnum) { 412 if (argAsEnum->base->name != resultAsEnum->base->name) { 413 return expr; 414 } 415 } 416 return ast::mutate_field( expr->arg.get(), 417 &ast::Expr::env, expr->env.get() ); 418 } 419 return expr; 402 return expr; 403 } 404 PRINT( 405 std::cerr << "types are compatible, removing cast: " << expr << '\n'; 406 std::cerr << "-- " << expr->result << '\n'; 407 std::cerr << "-- " << expr->arg->result << std::endl; 408 ) 409 return ast::mutate_field( expr->arg.get(), 410 &ast::Expr::env, expr->env.get() ); 420 411 } 421 412 }
Note: See TracChangeset
for help on using the changeset viewer.