LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 40670 - [RFE] allow assign to members of rvalue aggregate (-fpermissive)
Summary: [RFE] allow assign to members of rvalue aggregate (-fpermissive)
Status: NEW
Alias: None
Product: clang
Classification: Unclassified
Component: C++ (show other bugs)
Version: unspecified
Hardware: PC Linux
: P enhancement
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-02-08 14:36 PST by stsp
Modified: 2019-02-12 12:58 PST (History)
5 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description stsp 2019-02-08 14:36:06 PST
#include <iostream>
#include <cstdlib>
class s {
public:
    int a;
    ~s() { std::cout << "a=" << a << std::endl; }
};
static s foo()
{
    return s{0};
}
int main()
{
    foo().a = 5;
    int *p = std::malloc(sizeof(int));
    return *p;
}
---

This code can be compiled with g++ if -fpermissive is used.
clang++ doesn't compile it with any options.
Comment 1 stsp 2019-02-08 14:39:02 PST
https://lkml.org/lkml/2018/9/13/1272
LKML people also seem to want -fpermissive, and
overall google shows quite a lot of demand.
Comment 2 stsp 2019-02-11 08:57:12 PST
This example demonstrates permissive conversion from
void*, and also an extension to write fields of an aggregate
returned as rvalue. This is a useful extension, because
in the destructor you can have the use of the altered fields,
as the example demonstrates. This is a main motivation why
I think -fpermissive should be supported (permissive conversions
are not so important). g++ supports both, and probably more
extensions under -fpermissive (can't find the exact docs).
Comment 3 Richard Smith 2019-02-11 18:33:13 PST
A general "support -fpermissive" bug is too vague to be actionable -- -fpermissive covers a lot of GNU extensions, some of which we already implement, some of which might be useful but are not currently supported in Clang, and others of which we might want to specifically take a stand against implementing.

Can we repurpose this bug to specifically be about assigning to a subobject of a temporary?

(Incidentally, we should likely also add direct support for a -fpermissive flag, and make it downgrade all of our error-by-default extensions into warnings.)
Comment 4 stsp 2019-02-12 07:53:36 PST
(In reply to Richard Smith from comment #3)
> Can we repurpose this bug to specifically be about assigning to a subobject
> of a temporary?

Not sure what is the best way of repurpose.
I changed the description.
But will it be activated with -fpermissive, or otherwise?

> (Incidentally, we should likely also add direct support for a -fpermissive
> flag, and make it downgrade all of our error-by-default extensions into
> warnings.)

Would be good.
AFAIK this is all it does.
Comment 5 stsp 2019-02-12 08:49:38 PST
By the way,
https://en.cppreference.com/w/cpp/language/implicit_conversion#Temporary_materialization

The standard seems to say that a temporary materialization
occurs "when performing a member access on a class prvalue;",
which seems to be the case here.
So I even wonder why it is not assignable by default?
Is materialization not sufficient to became assignable?
Comment 6 Richard Smith 2019-02-12 12:58:01 PST
Temporary materialization conversion converts the s prvalue to an s xvalue. Class member access then gives an int xvalue. Assignment needs an lvalue; an xvalue won't do.