From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10974 invoked by alias); 14 Apr 2012 21:25:49 -0000 Received: (qmail 10958 invoked by uid 22791); 14 Apr 2012 21:25:48 -0000 X-SWARE-Spam-Status: No, hits=-5.7 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-iy0-f175.google.com (HELO mail-iy0-f175.google.com) (209.85.210.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 14 Apr 2012 21:25:35 +0000 Received: by iaag37 with SMTP id g37so6107723iaa.20 for ; Sat, 14 Apr 2012 14:25:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:x-system-of-record:x-gm-message-state; bh=4KBeAyPMAyO5674VsL8Ibge8NUj3CWFp3NZCSjLuaHk=; b=oUMsVIfFvB543WgPsbGBWyM4kKfnJqN0kLVnUTaW/EqpJt1PQ2YnSAeqBAx9tDBYg/ Ex0Ibi2L9ZHrq+jhzdzLTt97dkuLjEWU9jCJQpq+4tQVH1hdHPJb7qaQshbuhw5Z6tZq OhNqN88KEddQ1F1+jfExT3vPOrfcUhA/QbN4VNLh0QfPMhGWj9s2BakYlWiOu5hqQEl5 rOCwUgONAPZIRBv5gwnUElLUTxyqZ6X+jsu4UCnEYU2df/I7BhzlOxNKKS4Oc3VambxN RrtkNpBK0lW7qPiTXcxuXl3CmsbUmrJTfz2zTTeXIJ9julZKtFmNFJdUhMrZjJ+wLsK5 HRDg== Received: by 10.50.191.200 with SMTP id ha8mr902587igc.45.1334438735273; Sat, 14 Apr 2012 14:25:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.191.200 with SMTP id ha8mr902571igc.45.1334438735146; Sat, 14 Apr 2012 14:25:35 -0700 (PDT) Received: by 10.231.210.134 with HTTP; Sat, 14 Apr 2012 14:25:34 -0700 (PDT) In-Reply-To: References: <4F7B356E.9080003@google.com> <4F7C35A3.3080207@codesourcery.com> Date: Sat, 14 Apr 2012 21:25:00 -0000 Message-ID: Subject: Re: Switching to C++ by default in 4.8 From: Lawrence Crowl To: Chiheng Xu Cc: Richard Guenther , Bernd Schmidt , Gabriel Dos Reis , David Edelsohn , Diego Novillo , gcc Content-Type: text/plain; charset=ISO-8859-1 X-System-Of-Record: true X-Gm-Message-State: ALoCoQnDM3RwYsXxYzPYsY/r1K0HwyahMJ+Q3n/PBagZzcMY2N+Kj9F5n/dx2yhkEuZkXida/eC8b4ijK50CTqEQ6Vb8vnNE8xnhY54oUvGdvjE/gpROd6/ST4/JTU+5NMvO/sJtlQC9 X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2012-04/txt/msg00646.txt.bz2 On 4/13/12, Chiheng Xu wrote: > On Apr 9, 2012, Richard Guenther wrote: >>> Certainly there are cases where the type must be made more specific, >>> and getting the wrong type here would necessarily be a dynamic check. >>> However, the number of dynamic checks can be substantially reduced. >>> To provide a specific example, suppose I have a common_decl *p and >>> need to do extra work if it is a var_decl. >>> >>> do_general_work (p); >>> if (var_decl *q = p->to_var ()) >>> { >>> do_var_work_1 (q); >>> do_var_work_2 (q); >>> do_var_work_3 (q); >>> do_var_work_4 (q); >>> } >>> >>> The only dynamic work is in the pointer conversion. All other >>> function calls can be statically typed. >> >> Ok. But the above represents a completely different programming >> style than what we use currently. We do >> >> if (is_var_decl (p)) >> { >> do_var_work_1 (p); >> ... >> } >> >> so what I was refering to was static errors we get when we are >> able to promote function argument / return types to more specific >> sub-classes. > > What about this: > if(is_var_decl(p)) { > var_decl * p_var_decl = (var_decl *) p; > do_var_work_1 (p_var_decl); > }else if(is_type_decl(p)){ > type_decl * p_type_decl = (type_decl *) p; > do_type_work_2 (p_type_decl); > }else if(is_field_decl(p)){ > field_decl * p_field_decl = (field_decl *) p; > do_field_work_3 (p_field_decl); > } That approach will certainly work, but makes the correctness of the assignment contingent on the condition being right. If the condition changes in appropriately, you can get a bug. Even so, I think what you suggest is a good intermediate step. -- Lawrence Crowl