From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 74524 invoked by alias); 12 Nov 2015 11:42:08 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 74509 invoked by uid 89); 12 Nov 2015 11:42:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.1 required=5.0 tests=AWL,BAYES_50,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Thu, 12 Nov 2015 11:42:07 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 7362C29957; Thu, 12 Nov 2015 06:42:05 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id nf6YQuoQJeXP; Thu, 12 Nov 2015 06:42:05 -0500 (EST) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 63A421163A1; Thu, 12 Nov 2015 06:42:05 -0500 (EST) Received: by tron.gnat.com (Postfix, from userid 4192) id 5C01E1A5; Thu, 12 Nov 2015 06:42:05 -0500 (EST) Date: Thu, 12 Nov 2015 11:42:00 -0000 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Thomas Quinot Subject: [Ada] Crash on inconsistent IF-expression Message-ID: <20151112114205.GA72284@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="PNTmBPCT7hxwcZjr" Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-SW-Source: 2015-11/txt/msg01495.txt.bz2 --PNTmBPCT7hxwcZjr Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 926 This change makes sure the compiler produces a proper error (rather than crash) when compiling an (illegal) IF-expression where THEN-expression is overloaded, and none of its interpretation is compatible with the ELSE-expression. The following compilation must display: $ gcc -c badelse.adb badelse.adb:4:50: type incompatible with that of "then" expression package Badelse is type K is (Unknown, Blue, Red); type Tristate is (False, True, Unknown); Boo : Boolean; procedure P (X : K); end Badelse; package body Badelse is procedure P (X : K) is begin Boo := (if X = Unknown then Unknown else X = Blue); end P; end Badelse; Tested on x86_64-pc-linux-gnu, committed on trunk 2015-11-12 Thomas Quinot * sem_ch4.adb (analyze_If_Expression): Reject IF-expression where THEN-expression is overloaded and none of its interpretation is compatible with the ELSE-expression. --PNTmBPCT7hxwcZjr Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=difs Content-length: 712 Index: sem_ch4.adb =================================================================== --- sem_ch4.adb (revision 230239) +++ sem_ch4.adb (working copy) @@ -2191,6 +2191,17 @@ Get_Next_Interp (I, It); end loop; + + -- If no valid interpretation has been found, then the type of + -- the ELSE expression does not match any interpretation of + -- the THEN expression. + + if Etype (N) = Any_Type then + Error_Msg_N + ("type incompatible with that of `THEN` expression", + Else_Expr); + return; + end if; end; end if; end Analyze_If_Expression; --PNTmBPCT7hxwcZjr--