this is not standard compliant right?

vc14 allows this, and it works fine in debug and release:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <string>
#include <iostream>

struct what
{
    std::string s;
};

_declspec(noinline) void func(what& rwhat) 
{
    std::cout << rwhat.s;
}

int main()
{
    func(what{"slkdjflsf"});
//func({"what"}); //doesn't work thought as temporary is implicitely built from init list
    return 0;
}

Last edited on
A temporary object can't bind to non-const reference so this should not work in a standard compliant compiler.
thanks, thought so. can see why they allow it though as type is exact match - but don't think they should be doing it imo.
Last edited on
Topic archived. No new replies allowed.