Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3221828
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:55:16+00:00 2026-05-17T15:55:16+00:00

I am reposting a comp.std.c++ Usenet discussion here because that group has become very

  • 0

I am reposting a comp.std.c++ Usenet discussion here because that group has become very unreliable. The last few posts I’ve submitted there have gone into the void, and activity has all but ceased. I doubt I’ve been banned and/or everyone else just lost interest. Hopefully all interested people will find this discussion, and there will be a general migration. Maybe then they will appoint a new moderator.


Hello!

With my current interpretation of draft N3126 w.r.t. the conditional
operator and xvalues, I expect the following assertions to hold:

 int i = 0;
 int& j = true? i : i;
 int&& k = true? std::move(i) : std::move(i);   // #2
 assert(&i == &j); // Holds since C++98
 assert(&i == &k); // Should this hold as well?

5.16/4 says:

If the second and third operands [to
the conditional operator] are
glvalues of the same value category
and have the same type, the result is
of that type and value category […]

Though, it doesn’t clearly say that the resulting glvalue refers to
one of the objects the glvalue operands referred to — or is this
implied because otherwise it would return a prvalue? Using GCC 4.5.1
in C++0x mode the second assertion fails. The reference k seems to
refer to some temporary object. Can somebody clarify whether the
comiler is allowed to create such a temporary in case both operands
around the colon are xvalues of the same type?

I’m currently assuming GCC is buggy and/or not up-to-date with respect
to xvalues.

The followup question is: Wouldn’t it be nice to be able to detect the
value category of an expression? If we ignore the conditional operator
we can detect the value category of an expression with decltype. But
what is

 bool xvalue = std::is_rvalue_reference<
   decltype( true ? std::move(i) : std::move(i) ) >::value;

supposed to yield? Using GCC 4.5.1, the xvalue variable is initialized
with false. Is this conforming to the current standard draft?

TIA,
Sebastian

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:55:17+00:00Added an answer on May 17, 2026 at 3:55 pm

    I think GCC 4.5.1 is nonconforming wrt §5.16/4. Have you filed a bug report?

    Anyway, I think it is conforming with that ternary operator code. decltype is defined by §7.1.6.2/4:

    The type denoted by decltype(e) is
    defined as follows:

    • if e is an unparenthesized id-expression or a class member access
      (5.2.5), decltype(e) is the type of
      the entity named by e. If there is no
      such entity, or if e names a set of
      overloaded functions, the program is
      ill-formed;
    • otherwise, if e is a function call (5.2.2) or an invocation of an
      overloaded operator (parentheses
      around e are ignored), decltype(e) is
      the return type of the statically
      chosen function;
    • otherwise, if e is an lvalue, decltype(e) is T&, where T is the type
      of e;
    • otherwise, decltype(e) is the type of e. The operand of the decltype
      specifier is an unevaluated operand
      (Clause 5).

    decltype works by fetching the appropriate declaration and returning the desired type from it. It has little intelligence with respect to non-overloaded operators. Perhaps another point

    • otherwise, if e is an xvalue, decltype(e) is T&&, where T is the type of e

    would be in order, particularly since, as written, xvalues get treated as prvalues. Furthermore, your expression corresponds exactly to the definition of std::common_type (§20.7.6.6/3).

    One straightforward workaround (to coin a phrase :vP ):

    template< typename T1, typename T2 >
    struct common_type_and_category {
        typedef typename std::conditional<
            std::is_same< T1, T2 >::value,
            T1,
            typename std::common_type< T1, T2 >::type
        >::type type;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just reposting to make this clearer & because I've uploaded a sample of
I am reposting this question due to inability to solve the problem (original here
Perhaps my last question (now deleted) was misunderstood so I'm reposting it with more
I posted this question last week, but I wasn't very clear on what was
I am reposting this as my older post was not very clear. I have
i'm reposting this question because i'm not sure if i asked it correctly before.:)
I'm reposting this question as I didn't get much of a response last time,
Ayende has a great example of using the <any> mapping here , which I
I'm actually reposting a question from the iphone development boards. I didn't ask it,
We have a reporting solution that works like this. User orders the report to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.