public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "daniel.kruegler at googlemail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/57599] result of dynamic_cast<cv T> is just T
Date: Thu, 13 Jun 2013 06:59:00 -0000	[thread overview]
Message-ID: <bug-57599-4-4bQ0A8x4lg@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-57599-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57599

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler@googlemail.
                   |                            |com

--- Comment #4 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
I created a test case for all type conversion operators:

struct A {};
struct B : public A {};

template<class, class>
struct is_same { static constexpr bool value = false; };

template<class T>
struct is_same<T, T> { static constexpr bool value = true; };

template<class T>
T val();

static_assert(is_same<decltype(static_cast<const A*>(val<B*>())), const
A*>::value, "Ouch");
static_assert(is_same<decltype(static_cast<const A&>(val<B&>())), const
A&>::value, "Ouch");

static_assert(is_same<decltype(const_cast<const A*>(val<A*>())), const
A*>::value, "Ouch");
static_assert(is_same<decltype(const_cast<const A&>(val<A&>())), const
A&>::value, "Ouch");

static_assert(is_same<decltype(reinterpret_cast<const A*>(val<B*>())), const
A*>::value, "Ouch");
static_assert(is_same<decltype(reinterpret_cast<const A&>(val<B&>())), const
A&>::value, "Ouch");

static_assert(is_same<decltype(dynamic_cast<const A*>(val<B*>())), const
A*>::value, "Ouch"); // Error!
static_assert(is_same<decltype(dynamic_cast<const A&>(val<B&>())), const
A&>::value, "Ouch"); // Error!

In agreement with that bug report I see failures for the last two even for gcc
4.9.0 20130609 (experimental)
>From gcc-bugs-return-424283-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Jun 13 07:00:07 2013
Return-Path: <gcc-bugs-return-424283-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 9192 invoked by alias); 13 Jun 2013 07:00:06 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 9130 invoked by uid 48); 13 Jun 2013 07:00:03 -0000
From: "valeryweber at hotmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/57596] select type bug with optional variables?
Date: Thu, 13 Jun 2013 07:00:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: fortran
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: valeryweber at hotmail dot com
X-Bugzilla-Status: RESOLVED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-57596-4-CoXWze0iVG@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-57596-4@http.gcc.gnu.org/bugzilla/>
References: <bug-57596-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-06/txt/msg00662.txt.bz2
Content-length: 1277

http://gcc.gnu.org/bugzilla/show_bug.cgi?idW596

--- Comment #2 from Valery Weber <valeryweber at hotmail dot com> ---
But the selector is not optional. The problem even remains if I
move the optional variables outside the SELECT TYPE (see bellow).
Those 2 codes run just fine with other compilers like ifort or xlf.
Thanks
Valery


MODULE base_types
  TYPE :: base_integer_type
     INTEGER :: i
  END TYPE base_integer_type
  TYPE :: base_character_type
     CHARACTER( 10 ) :: c
  END TYPE base_character_type
END MODULE base_types

PROGRAM main
  USE base_types
  IMPLICIT NONE
  INTEGER::i_val
  call get (  i_val=i_val )
  write(*,*) 'i_val',i_val
contains

  SUBROUTINE get (i_val, c_val)
    INTEGER, INTENT( OUT ), OPTIONAL :: i_val
    CHARACTER( : ), INTENT( OUT ), ALLOCATABLE, OPTIONAL :: c_val
    CLASS( * ), POINTER :: p
    TYPE( base_integer_type ),target :: i_base
    INTEGER :: i_val_tmp
    CHARACTER( 10 ) :: c_val_tmp
    i_base%i=-12
    p=>i_base
    SELECT TYPE( p )
    TYPE IS( base_integer_type )
       i_val_tmp = p%i
    TYPE IS( base_character_type )
       c_val_tmp = p%c
    CLASS DEFAULT
       stop
    END SELECT
    IF(present(i_val)) i_val = i_val_tmp
    if(present(c_val)) c_val = c_val_tmp
  END SUBROUTINE get
END PROGRAM main


  parent reply	other threads:[~2013-06-13  6:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-12 16:30 [Bug c++/57599] New: g++ accepts invalid dynamic_cast of a const type to a regular type abel at gcc dot gnu.org
2013-06-12 16:35 ` [Bug c++/57599] " redi at gcc dot gnu.org
2013-06-12 16:38 ` [Bug c++/57599] g++ accepts invalid assignment of a dynamic_cast<const A*> to A* abel at gcc dot gnu.org
2013-06-12 23:34 ` [Bug c++/57599] result of dynamic_cast<cv T> is just T paolo.carlini at oracle dot com
2013-06-13  6:59 ` daniel.kruegler at googlemail dot com [this message]
2013-06-13  7:03 ` abel at gcc dot gnu.org
2013-06-14  9:23 ` paolo.carlini at oracle dot com
2013-06-14  9:37 ` abel at gcc dot gnu.org
2013-06-14 10:17 ` paolo.carlini at oracle dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-57599-4-4bQ0A8x4lg@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).