Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #775

Template argument name resolution and compiler discrepancies

Path csiph.com!xmission!news.glorb.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!Xl.tags.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date Sat, 12 Sep 2015 11:30:02 -0500
Return-Path <cppmods@glengoyne.dreamhost.com>
Sender std-cpp-request@vandevoorde.com
Approved james.dennett@gmail.com
Message-ID <45eda1c8-7f97-40eb-9877-709c5c7585a2@googlegroups.com> (permalink)
Newsgroups comp.std.c++
From Jonathan Jones <jhjones1969@googlemail.com>
Subject Template argument name resolution and compiler discrepancies
Organization unknown
Content-Type text/plain; charset=ISO-8859-1
X-Original-Date Fri, 11 Sep 2015 10:54:24 -0700 (PDT)
X-Submission-Address std-cpp-submit@vandevoorde.com
Date Sat, 12 Sep 2015 11:24:16 CST
Lines 54
X-Usenet-Provider http://www.giganews.com
X-Trace sv3-OxZsjMssgvSyIgMaHVo2FSwKztwKCb002R0Twx9vwv6+9rAaE0i4uLvExveWSR6eNgaKNVX1CLkYC7I!LcXpGIEYgLcfjy5H+32midJAxPR6MjUXGt7rMSoZD/hhF+Te5Dvb/pd3V/x5IbZm1GI0ikd3Nt5p!EZ//CPvBY4M=
X-Complaints-To abuse@giganews.com
X-DMCA-Notifications http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 2803
X-Received-Bytes 2915
X-Received-Body-CRC 2207180987
Xref csiph.com comp.std.c++:775

Show key headers only | View raw


Hi folks,

Look at the following example code:

    template<typename>
    class Base
    {
        typedef int ValueType;
    };

    template<typename ValueType>
    struct Derived : public Base<ValueType>
    {
        Derived(ValueType);
    };

    Derived<float> obj(1);

This code compiles cleanly with GCC 4.7.2 and Clang 3.5 (Xcode 6.2).
However, it fails to compile with Visual Studio 2013, complaining that it
cannot access private typedef "Base<ValueType>::ValueType".

Furthermore, if you make the private typedef public:

    template<typename>
    class Base
    {
    public:
        typedef int ValueType;
    };

It compiles on all three compilers, but the produces different answers.
GCC and clang result in ValueType=float in the Derived constructor
definition, whereas Visual Studio 2013 results in ValueType=int in the
Derived constructor definition.

What does the standard say should happen in these cases?  Which compiler(s)
are closer to implementing the standard behavior?

The standard is clear (see C++11 section 14.6.1 paragraph 9) about what
happens when "Base" is not a template, but it seems more vague about when
"Base" is a template (which the example above seems to demonstrate).

Sincerely,
Jonathan Jones


--
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]

Back to comp.std.c++ | Previous | NextNext in thread | Find similar


Thread

Template argument name resolution and compiler discrepancies Jonathan Jones <jhjones1969@googlemail.com> - 2015-09-12 11:24 -0600
  Re: Template argument name resolution and compiler discrepancies Bo Persson <bop@gmb.dk> - 2015-09-13 07:51 -0600

csiph-web