« first day (584 days earlier)      last day (4367 days later) » 

1:00 AM
Good choice?
 
really, weird
 
Xeo
"Learn C The Hard Way"
 
I am reading it now..
 
Xeo
Didn't you want to learn C++?
 
oh right..
I will go for the c++ version if applicable
 
Xeo
1:02 AM
And I can now confirm that VC drops all cv qualifiers, not even volatile is safe
 
nope, no C++ version, then I'll read the book of the C++ creator..
 
Xeo
@Tony rawr
 
@Xeo but only in trailing return type decltype?
 
Xeo
yes
 
so basically, their trailing return type code is completely half-assed, but only if it uses an overloaded operator, not if it calls the same operator function by name
 
Xeo
1:04 AM
struct X{};

bool operator>(X& a, int& b){ return true; }

int main(void) {
  X const x; int i = 6;
  decltype(x > i);
}
correctly fails to compile
 
wtf is up with that crap
 
Xeo
Bug, happens to the best
 
no but why doesn't > simply immediately evaluate to operator> ?
 
Xeo
member & free overloads
you can't call the member overload with operator>(...)
 
refer to code: ideone.com/9OtdZ
that's not a member overload
it's a free one
 
Xeo
1:07 AM
Yes, but I just answered your question as to why x > y doesn't immediately evaluate to operator>(x,y)
(if that actually was your question)
Man, I hate that Connect removes leading whitespace in comments...
 
...how did you answer it? :-\
 
Xeo
x > y is not allowed to immediately evaluate to operator>(x,y) because operators can be overloaded as free functions and as member functions. operator>(x,y) would only look at the free overloads, while member overloads need to be called with x.operator>(y)
 
ahh.
maybe therein is the bug
 
Xeo
Well, member overloads actually get a synthesized form for the overload resolution
struct X{
  bool operator<(int){ return true; }
};

bool operator<(X const&, int){ return true; }

int main(){ X x; x < 5; }
 
...
are you saying that that gets synthesized
 
Xeo
1:13 AM
Takes this code, the overload set will contain operator<_synth(X& implicit_object, int) (which is linked to the member) and operator<(X const&, int)
 
Xeo
28
A: What is "rvalue reference for *this"?

XeoFirst, "ref-qualifiers for *this" is a just a "marketing statement". The type of *this never changes, see the bottom of this post. It's way easier to understand it with this wording though. Next, the following code chooses the function to be called based on the ref-qualifier of the "implicit obj...

At the bottom part of this answer I explain a bit how overload resolution and how the transformation / synthesization works
 
dude @Xeo wtf
 
Xeo
I love digging in the standard :D
 
that makes my longest most in-depth answer look like a one-line reply "yes"
and I dug slightly into CLI internals for it :-(
 
Xeo
1:16 AM
Look at some of the answers and come back ;P
 
@Xeo ohai
 
@TonyTheLion ohio
 
hi
whassup?
 
@TonyTheLion asia
 
1:17 AM
we're just figuring out why MS are such fuckups, as usual, and doing their work for them by submitting meticulously detailed bug reports
@TonyTheLion also courtesy of @CheersandhthAlf i.stack.imgur.com/0V2f6.jpg icanhascheezburger.files.wordpress.com/2010/11/… in that order
 
Xeo
@stdOrgnlDave RE that, at first I had another thought going on
You know how MSVC allows temporaries to be bound to T& (aka ref-to-non-const)?
 
is that non-standard behavior? do I even need to ask?
 
Xeo
non-standard, yes
I thought that maybe MSVC created a copy of the parameter inside the decltype and used that for overload resolution...
Now that I'm thinking back, I don't even know if I correctly checked that it does not...
brb
 
hmm that's interesting
 
Xeo
1:25 AM
FUCK THIS!
2
 
????
WAAAAA
 
Xeo
struct X{
    X(){}
private:
    X(X const&);
};

bool operator>(X& a, int& b){ return true; }

template<class T, class U>
auto operator<(T const& v, U const& u) -> decltype(v > u){ return true; }

int main(void) {
  X x; int i = 6;
  x < i;
}
compiles
That was the only thing I tested back then
 
I'm not sure what the problem is there, other than the fact that it compiles
that private constructor isn't called...
 
Xeo
Now let's add another ctor:
struct X{
    X(){}
private:
    X(X const&);
    template<class T>
    X(T&&);  // <<==
};
Guess what
 
wtf
wtf why would you do that
 
Xeo
1:27 AM
MSVC fails to compile
@stdOrgnlDave To see if MSVC does anything weird, and it indeed does
 
should it not fail to compile all of a sudden?
ahhh
 
Xeo
1>src\main.cpp(28): error C2248: 'X::X' : cannot access private member declared in class 'X'
1>          src\main.cpp(18) : see declaration of 'X::X'
1>          src\main.cpp(13) : see declaration of 'X'
 
so why the fuck is it calling that constructor
 
Xeo
It somehow tries to copy the object, but not through the copy ctor (unless I overlooked another construction in that code...)
Wow, seriously wow.
So it's not overload resolution that's fucked up...
 
it runs deeper than that. MSVC be rotten to the core she do be yes
 
Xeo
1:31 AM
Even disabling language extensions (to disable that "temporary to non-const-ref binding) doesn't work
Still compiles (if you remove the private ctor)
huh
Okay, now I'm deeply confused
Even with language extensions enabled, int& i = 5 doesn't work. Did they fix that for VC11?!
 
@Xeo I think we're learning a bigger lesson here. the closer you peer at the internals of VC, the more insane you go. it's Microsoft Lovecraft C++
 
Xeo
@stdOrgnlDave, can you try with VC10?
 
int& i = 5 or the other thing>
 
Xeo
former
 
1>c:\dev\btest3\btest3\main.cpp(97): error C2440: 'initializing' : cannot convert from 'int' to 'int &'
 
Xeo
1:33 AM
wat.
I clearly remember that MSVC allows temporaries to be bound to non-const lvalue refs...
 
can't find language extensions
 
Xeo
Ah
X& x = X() compiles
So it has to be a user-defined type
@stdOrgnlDave Properties -> C/C++ -> Language, first option
 
1>c:\dev\btest3\btest3\main.cpp(97): error C2440: 'initializing' : cannot convert from 'int' to 'int &'
with them disabled
 
Xeo
Needs to be a user-defined type
 
so...do you want me to do something?
 
Xeo
1:36 AM
And even disabling the language extensions doesn't cause it to error, this particular extension is just not disableable!
(Do I need to mention that "disableable" is a really weird word?)
In any case, I think we're close to discovering the truth
MSVC tries to create an X temporary from something other than the supplied x argument (it does not call the copy ctor)
 
I think the truth may very well drive you mad, Xeo
maybe you've gone too far this time
 
Xeo
Then so be it! My sanity for the sake of finally getting this out of my head!
Sanity is just a mask, anyways.
 
now that I have actually put the code in myself and tried to run it it is bother me too
I wish I had a compiler meta-debugger or something
 
Xeo
Erm...
wat. again.
 
@Xeo
template<class T>
X(T);  // <<==
that causes the same error
it doesn't have to be an rvalue reference
 
Xeo
1:41 AM
@stdOrgnlDave That wasn't an rvalue ref, it was perfect forwarding
So, we just found out that "temporary to lvalue non-const ref" only works for user-defined types, right?
bool operator>(X& a, int& b){ return true; }
//                   ^^^^^^
 
ummm, sure.
 
Xeo
Why does it discard the const for the int argument too, then?
 
I wondered that myself. I gave it explicit const int and it didn't care
 
Xeo
Even if it creates a temporary out of nowhere, the lvalue-non-const-ref-to-temporary business should only work for UDTs....
 
just in case it wasn't treating a constant as a constant, I declared "const int b"
 
Xeo
1:44 AM
Gaaaah
This is so fucked up, I don't know where to start.
 
what if we compare 2 user-defined types like this?
one with that private constructor, one without?
change which one has it
 
Xeo
We now have two possible culprits
 
give them both it
see which one it complains about
if X and Y both have it, but the compiler only complains about Y, we have learned something
 
Xeo
@stdOrgnlDave For testing's sake, I even flipped the parameters of operator>
 
hmmm. OK, what about moving decltype back into main?
 
Xeo
1:45 AM
(and the arguments too, of course, aka 5 < x)
normal decltype works correctly
it's only in trailing return type that it fucks up
 
I thought that...ok
maybe we're looking at this from the wrong angle
 
Xeo
Okay, now, the culprits: Either major decltype fuck up that discards cv qualifiers during overload resolution when used in a trailing return type, or major language extension fuck up that creates temporaries out of nowhere with an argument that's not the same type
 
what does a compiler do when it encounters a template with a trailing return type?
 
Xeo
no idea
 
it attempts to instantiate said template, which generates code, by using compile-time information to deduce the return type
 
Xeo
1:49 AM
Okay, another interesting fact: MSVC does not only discard cv qualifiers, it also discards rvalueness
struct X{
};

bool operator>(X& a, int& b){ return true; }

template<class T>
auto operator<(T const& v, int&&) -> decltype(v > int()){ return true; }

int main(void) {
  X x;
  x < 6;
}
 
what?
wtf?
 
Xeo
Again, this may be related to that language extension, but our testing showed that that shouldn't apply to built-in types
 
that builds on VC10 btw
 
Xeo
Yes, on VC11 too
that's what bothers me
It should not
 
Xeo
1:52 AM
Man, and here I thought I could leisurely spend the night playing games...
 
GCC at least is sane
 
Xeo
@stdOrgnlDave sure, it was sane from the get go (in this case, atleast)
 
Hi
@stdOrgnlDave I'm having a C++ problem.
 
@moshe moshi moshiiii
@Moshe 'sup
 
lol
@stdOrgnlDave I have this class that uses the C string class we discussed a while ago.
 
1:53 AM
watch out I don't drive you insane like I am @Xeo
@Xeo the weirdest thing for me is that this behavior is absolutely identical between VC10 and VC11, like they left this part of the code completely alone while they updated other C++11 core features
@Moshe you do.
 
Xeo
Wat.
struct X{
    X(){}
private:
    X(int){}
};

bool operator>(X& a, int& b){ return true; }

template<class T, class U>
auto operator<(T const& v, U const&) -> decltype(v > 2.5){ return true; }

int main(void) {
  X x;
  x < 6;
}
Oh, ignore the 2.5 there
 
Xeo
Errors out
 
Xeo
it calls the X(int) ctor
 
1:54 AM
@stdOrgnlDave Yea, and instead of declaring a new mycstring in each function, I want to have a class member.
 
Xeo
For whatever unholy reason.
 
But it breaks inside of operator overloads.
 
because it isn't explicit?
even though it shouldn't be able to since it's private
hey, @Xeo, for the heck of it, what if you make these protected and not private?
 
@stdOrgnlDave Wait, who are you talking to?
 
Xeo
@stdOrgnlDave It calls and fails to compile, because it's private
 
1:55 AM
@Moshe of course it does
 
 member function ‘bool MyString::operator==(const MyString&) const’:
mystring.cpp:68: error: passing ‘const mycstring’ as ‘this’ argument of ‘int mycstring::mystrcmp(const char*, const char*)’ discards qualifiers
 
Xeo
@stdOrgnlDave Same error
 
@stdOrgnlDave Why?
 
@Xeo no I mean with the template<T>X(T&&)
 
@Moshe You're calling mystrcmp from operator==, but you can't because in the latter *this is const-qualified while mystrcmp expects a non-const-qualified *this.
 
Xeo
1:56 AM
one sec
Now MSVC is really pushing my mental limits
 
@xeo did it make a difference?
 
Xeo
no
But I also tested something else
 
@LucDanton So how do I fix that?
Oh, this.mystrcmp?
 
Xeo
@stdOrgnlDave, check this: If you do not declare any private ctor, it compiles. If you declare a private ctor that takes an int (or anything an int can convert to), it does not compile (failed access to private ctor). If you declare any other private ctor, it compiles.
It's almost as if MSVC silently inserts a public X(int)...
 
but for what reason would it possibly do that?
 
2:01 AM
@Moshe I don't know. If mystrcmp really is a non-const operation, there is something broken in your design. If it isn't, then mark it const.
 
Xeo
Oh, yeah, making the private one X(int&) lets it compile again, X(int const&) does not
 
Xeo
X(int&&) compiles again
Same with X(int const&&)
Now we know that the argument to the ctor is definitly a const-lvalue int
 
X(double const&) compiles?
 
Xeo
X(double) atleast does not, sec
 
user406009
2:03 AM
I know I am probably going to sound like an idiot, but didn't access qualifiers not matter when it came to resolution of functions?
 
Xeo
X(double const&) doesn't compile either
 
@EthanSteinberg That is correct. (I.e. they're ignored.)
 
Xeo
Wait
 
@Xeo what if you declare a private ctor that takes a class that an int can implicitly convert to
 
Xeo
@LucDanton They're ignored for the lookup / overload resolution, but are checked after that
 
2:05 AM
The question was about resolution.
 
@LucDanton he's one step ahead of you
 
Xeo
@stdOrgnlDave compiles
 
@Xeo that's...odd.
 
Xeo
Indeed
 
you'd think that wouldn't compile, right?
 
Xeo
2:06 AM
Right, especially after finding out that X(double) does not compile
 
@Moshe you want help or not? answer me question in our room :-P
 
Xeo
Aside from all the discussion, I can safely say that MSVC introduced a 4th kind of behaviour, next to "undefined", "unspecified" and "implementation defined": "weird behaviour".
 
how about inexplicable behavior
here's what I think MSVC does
 
Xeo
Another good name
@stdOrgnlDave I don't really want to think about that...
 
I think that it seeds a random number generator with the hash of your code, then decides whether or not to compile this based on that
 
Xeo
2:09 AM
They must have some serious fuck ups in their code to call a non-existant ctor of a UDT
Seriously, I just don't get it anymore
 
maybe that's what they do, though
maybe they use an anonymous implicit ctor for this functionality
 
Xeo
wait
 
maybe for some reason that's how they implement trailing return types
 
Xeo
The argument to the ctor may not necessarily be an int
it may also just be something that converts to int, that's why the UDT with implicit conversion from int doesn't work
 
:-(
maybe...it is a const int?
or just a const& constructor
...um, you know what I mean
that would explain a lot
 
Xeo
2:13 AM
Yay, it gets even funnier
(I think I'm about to break.)
struct X{
    X(){}
private:
    X(int){}
};
does not compile
struct X{
    X(){}
    X(int const&){}
private:
    X(int){}
};
 
wait a second
 
Xeo
does compile
 
let's back up
we're doing a comparison of X<int
 
Xeo
even though overload resolution between X(int const&) and X(int) should be ambiguous
 
what if it is simply straight-out trying to compare X to int?
@Moshe plinkity
 
Xeo
2:15 AM
aha..ahahaha....ahahahahhaha....
struct X{};

bool operator>(int& a, X& b){ return true; }

template<class T>
auto operator<(T const& v, int const& u) -> decltype(v > u){ return true; }

int main(void) {
  X x;
  x < 6;
}
compiles.
 
Sec, sorry, afk for 10
 
yeah we already figured that out like 30 minutes ago
 
Xeo
@stdOrgnlDave No, look at the parameters of operator>
And at the arguments to operator<
 
wtf
!?
wtf!?!?!?
wtfcopter?
 
Xeo
Try that with MSVC10 please
 
2:17 AM
language extensions on?
 
Xeo
off
 
succeeded
 
Xeo
Well, fuck MSVC.
I'll flee into my little gaming world to escape this insanity. It's too much even for me.
 
wait
before you do that
remember this
struct X{};

bool operator>(int& a, X& b){ return true; }

template<class T>
auto operator<(T const& v, int const& u) -> decltype(operator>(v, u)){ return true; }

int main(void) {
  X x;
  x < 6;
}
doesn't compile
let that spin your head
wait a second!
 
Xeo
No, that is correct
We already found out that free form calling does result in the correct behaviour
 
2:21 AM
ROFL!
struct X{};

bool operator==(int& a, X& b){ return true; }

template<class T>
auto operator<(T const& v, int const& u) -> decltype(v>u){ return true; }

int main(void) {
  X x;
  x < 6;
}
 
Xeo
It's a weird mixed fuck up of trailing return decltype, operator overload resolution and VC's language extension
 
look at that
not even defining operator>
hahaha
sorry this just got really really funny to me
 
Xeo
Oh, you snapped too?
 
did you look at that last snippet?
I declared operator== and it accepted v>u
operator+ works too
 
Xeo
struct X{};

template<class T>
auto f(T const& v, int const& u) -> decltype(v > u){ return true; }

int main(void) {
  X x;
  f(x,6);
}
We can even drop the operator<
But we can't drop the template
 
2:25 AM
wait what?
OK now my head is broken
maybe it simply assumes that EVERY outcome of > is going to be bool no matter what?
 
Xeo
struct X{};

template<class T>
auto f(T const& v, int const& u) -> decltype(v[u]){ return true; }

int main(void) {
  X x;
  f(x,6);
}
fails
v == u compiles
 
i have a more practical problem, if i may?
 
Xeo
Sure
 
please
 
2:27 AM
my head is exploding
 
Xeo
But don't expect anything, our brains are mush right now
 
with wtf's @ microsoft
 
i thought this should work:
class NoTemporary
{
protected:
    ~NoTemporary() {}
public:
    NoTemporary() {}
    NoTemporary( NoTemporary&& other ) {}
};

NoTemporary selectObject() { return NoTemporary(); }
 
Xeo
What does not work?
 
But the compiler complains about access to destructor just for the definition of the function.
 
2:28 AM
by "work" you mean "stop it from making temporaries"?
 
Xeo
Sure, destructor always needs to be public if an instance of that static type is created (or even declared)
 
give exact error please?
 
The compiler in question is MSVC 10.0, if that helps?
1>d:\dev\test\mfc_graphics\mfc_graphicsdlg.cpp(143): error C2248: 'NoTemporary::~NoTemporary' : cannot access protected member declared in class 'NoTemporary'
 
@CheersandhthAlf d
well, I'm inclined to agree with @Xeo, but I still am curious if you make that 2 lines which one it will complain about: the declaration or the return
 
2:30 AM
lemme check
it's the return statement
but it should move the object and not invok
oh
 
VC10 doesn't have move semantics
 
Xeo
It does
 
what!?
since when!>
 
Xeo
But not full semantics :P
@CheersandhthAlf Even if it moves, it has to call the dtor
 
2:32 AM
i was stupid, sorry
but what is good solution?
 
@Xeo that's true
make more of the ctors private
 
Xeo
I don't think you can effectively prevent temporaries without going the factory route. And I don't really understand why you would want to
 
return TemporaryPreventionFactoryTemplate<NoTemporary>();
I love making fun of factories
 
i want to force storing the function result. in order to guarantee cleanup. of a windows dc
 
Xeo
Oh, so you don't want just selectObject(...); as a codeline
 
2:34 AM
right
i want to force
Cleanup cleanup = selectObject()
 
Xeo
Bjarne pondered about adding an operator void() to allow checking if a temporary is discarded
but currently, it's not possible to force that, I think.
 
wait, does boost have a hack for this?
 
Xeo
Unless you just return the Cleanup object and, well, if it isn't stored, fuck the user, the resource gets cleaned up
 
always check boost
 
@CheersandhthAlf Not doable IIRC.
 
2:36 AM
@Xeo in the standard is it guarenteed that the only return type possible from a comparison operator with an int is a bool?
 
Xeo
@stdOrgnlDave no, only the number of arguments is specified
 
@Xeo we should look at the assembly output of the really fucked up ones
 
@Xeo well there is the idiom of throwing from destructor of unused object
 
see what the strange code it generates actgually does
 
dynamic checking
:(
 
Xeo
2:38 AM
@CheersandhthAlf How do you check if the object is unused? If it isn't used to initialize a certain other object?
 
Xeo
Well, I'd just return a Cleanup object and be done with it, I think. If the user doesn't store, well.. his fault, I guess
 
thinking about it it has to be a CleanupSpec, to be used to initialize a Cleanup
 
Lock-guard style usage comes to mind though. You want static correctness for those things.
 
otherwise would need ref counting in order to cleanup just once
i think
 
2:40 AM
(Never mind that locks are cumbersome.)
 
Xeo
@CheersandhthAlf Or unique_ptr style, no copies.
 
@Xeo uhm, yes
 
Xeo
struct X{};

template<class T>
decltype(X() == int()) f(T const& v, int const& u){ return true; }

int main(void) {
  X x;
  f(x,6);
}
@stdOrgnlDave ^
compiles
 
OK if @moshe comes back tell him I'm sorry but not satying up til 3am to help him. if anyone wants to explain it, he is doing mystring.mystrcmp() but mystrcmp() is static so it needs to be mycstring::mystrcmp()
 
dunno if it's relevant, but it surprised me that C++11 decltype can tell you if something is a reference or an original variable. couldn't do that distinction in C++03.
 
Xeo
2:43 AM
I'll check the standard again to make sure comparision ops aren't forced to return bool...
 
@stdOrgnlDave the "." syntax is technically OK for static. it's just a bit misleading.
 
@CheersandhthAlf then why's it not work?
 
Xeo
(which in any case doesn't matter, since there is no operator== in the first place)
 
@stdOrgnlDave uh, what? i haven't seen the example. link?
 
49 mins ago, by Moshe
 member function ‘bool MyString::operator==(const MyString&) const’:
mystring.cpp:68: error: passing ‘const mycstring’ as ‘this’ argument of ‘int mycstring::mystrcmp(const char*, const char*)’ discards qualifiers
 
2:46 AM
@stdOrgnlDave Thanks, I'm sorry. It's only 10:45PM here, but I had to go afk sorta unexpectedly.
 
it's only 10:45PM here too but I need sleep :-P
@Xeo there's no chance it's thinking of a binary compare is there?
 
Xeo
0
Q: Why does the following code compile with MSVC++?

Xeostruct X{}; template<class T> decltype(X() == int()) f(T const&){ return true; } int main(void) { X x; f(x); } Why, just why? There is no operator== defined anywhere! Please enlighten me, please.

I give up. :P
 
53 mins ago, by Luc Danton
@Moshe You're calling mystrcmp from operator==, but you can't because in the latter *this is const-qualified while mystrcmp expects a non-const-qualified *this.
 
@LucDanton mystrcmp is a static member function
 
@stdOrgnlDave mkay gnight
 
2:52 AM
@Xeo if someone answers that I will worship them unless it is @DeadMG
@Moshe so does it work?
the suspense is boring me to death
goodnight all
@Xeo you should provide the private constructor that STOPS it from compiling as a contrast
 
Xeo
Good idea
 
@stdOrgnlDave Don't know yet.
Juggling a homework and a final.
Right now the final is winning.
 

« first day (584 days earlier)      last day (4367 days later) »