Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Big issue with Visual Studio 2019 (some versions)
Big issue with Visual Studio 2019 (some versions) [message #53011] Sat, 08 February 2020 02:19 Go to next message
Alboni is currently offline  Alboni
Messages: 191
Registered: January 2012
Location: Deventer, Netherlands
Experienced Member
Hello,
There is a big issue with Visual Studio 2019 (some versions)
The example gives a warning and with reason
It may seem like a small issue but it'd not. This is used all over UPP and TheIde.
I can't compile a working non crashing version of TheIde (and my sofware) with it.
It's roulette whether it works or not. On my collegues computer it works, on mine it doesn't

See example below.

#include <Core/Core.h>

using namespace Upp;

// this construction is used a lot in upp
String SomeFunction()
{
	StringBuffer s;
	s.Cat("M\0nkey", 6); // some binary data
	return s;  // warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied

	// this contruction (returning a StringBuffer to a String return type) is used a LOT in UPP
	// it relies on the constructor of String(StringBuffer& )  to do the copying
	// However another path is from StringBuffer::Begin() -> String::String(const char*)
	// this however does not work for binary data (containing a 0)
	// Visual Studio 2019 picks the first or the second option depending on which *EXACT* version of it you're using, and gives this warning that it flipped a coin
	// IT IS NOT A BENIGN WARNING! It's roulette if the software works or not.
	// I cannot compile a stable executable of TheIde with VS2019 on my computer. It just keeps
	// crashing. My collegue can. 
}

CONSOLE_APP_MAIN
{
	String rv = SomeFunction();
	Cout() << rv.GetCount() << "\r\n"; // Should print 6, but prints 1
}

[Updated on: Sat, 08 February 2020 11:52]

Report message to a moderator

Re: Big issue with Visual Studio 2019 (some versions) [message #53012 is a reply to message #53011] Sat, 08 February 2020 11:50 Go to previous messageGo to next message
Alboni is currently offline  Alboni
Messages: 191
Registered: January 2012
Location: Deventer, Netherlands
Experienced Member
If I make the following change:
//return s;
return String(s);


I get the correct results and the warning is gone.

I also tried changing it the same way in UPP in all 86 places (yes some were WString and there was a T) and that also works.

I can make a patch if that is appreciated.

Perhaps someone knows a more elegant solution?

Re: Big issue with Visual Studio 2019 (some versions) [message #53013 is a reply to message #53011] Sat, 08 February 2020 11:55 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12179
Registered: November 2005
Ultimate Member
Sad

It would be worth to write here explicit version of visual studio that mibehaves.

If it is the most recent, we can file a bug if we can simplify the issue to nonU++. Last time the fix was fast.

As everything seems to be fine with gcc and clang, I do not think we should hurry for workaround here.

Mirek
Re: Big issue with Visual Studio 2019 (some versions) [message #53014 is a reply to message #53013] Sat, 08 February 2020 13:02 Go to previous messageGo to next message
Alboni is currently offline  Alboni
Messages: 191
Registered: January 2012
Location: Deventer, Netherlands
Experienced Member
It is the most recent. I downloaded it yesterday.
I'll look up the exact number in a minute
Re: Big issue with Visual Studio 2019 (some versions) [message #53015 is a reply to message #53011] Sat, 08 February 2020 13:10 Go to previous messageGo to next message
Alboni is currently offline  Alboni
Messages: 191
Registered: January 2012
Location: Deventer, Netherlands
Experienced Member
index.php?t=getfile&id=5988&private=0
  • Attachment: vstudio.png
    (Size: 28.06KB, Downloaded 143 times)

[Updated on: Sat, 08 February 2020 13:10]

Report message to a moderator

Re: Big issue with Visual Studio 2019 (some versions) [message #53016 is a reply to message #53011] Sat, 08 February 2020 13:17 Go to previous messageGo to next message
Alboni is currently offline  Alboni
Messages: 191
Registered: January 2012
Location: Deventer, Netherlands
Experienced Member
My collegue's computer (on which it works without workaround) does still emit the warning....

[Updated on: Sat, 08 February 2020 13:17]

Report message to a moderator

Re: Big issue with Visual Studio 2019 (some versions) [message #53017 is a reply to message #53016] Sun, 09 February 2020 10:34 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12179
Registered: November 2005
Ultimate Member
OK, now I have to admit that I am reluctant to break my environment by downloading possibly broken compiler....

So thinks that come to mind:

- first of all, I believe that this is compiler bug, not ours, because operator char * is two conversions far, while StringBuffer is direct parameter. Do you agree?

- are you able to create some working single file testcase for microsoft?

- as much as I hate the idea, we can perhaps try workaround by removing String(StringBuffer&) constructor and adding operator String to StringBuffer.

Mirek
Re: Big issue with Visual Studio 2019 (some versions) [message #53018 is a reply to message #53011] Sun, 09 February 2020 14:33 Go to previous messageGo to next message
Alboni is currently offline  Alboni
Messages: 191
Registered: January 2012
Location: Deventer, Netherlands
Experienced Member
Yeah, don't break your computer.

I came up with this:

#include <iostream>

typedef unsigned char bYte;
#define min(a,b) ( a<b ? a : b )

class B;

class A {
	public:
		bYte data[256]; bYte datalen;
		
	public:
		A(const void* b, bYte len); // assign binary data
		A(char* string); // assign C string
		A(B& b);
		operator char*() // to c string
		{
			data[sizeof(data)-1]=0;
			return (char*)data;
		};
};

class B {
	public:
		bYte data[256]; bYte datalen;
		
	public:
		B(const void* b, bYte len); // assign binary data
		B(char* string); // assign C string
		operator char* ()  // to c string
		{
			data[sizeof(data)-1]=0;
			return (char*)data;
		}
};


A::A(const void* b, bYte len) // assign binary data
{
	datalen = min(len, sizeof(data)-1);
	memcpy(data, b, datalen);
	data[datalen]=0;
}

A::A(char* string) // assign C string
{
	datalen = min(strlen(string)+1, sizeof(data));
	memcpy(data, string, datalen);
	data[sizeof(data)-1]=0;
}

A::A(B& b)
{
	datalen = b.datalen;
	memcpy(data, b.data, sizeof(data));
}

B::B(const void* b, bYte len) // assign binary data
{
	datalen = min(len, sizeof(data)-1);
	memcpy(data, b, datalen);
	data[datalen]=0;
}

B::B(char* string) // assign C string
{
	datalen = min(strlen(string)+1, sizeof(data));
	memcpy(data, string, datalen);
	data[sizeof(data)-1]=0;
}

A ReturnB()
{
	const char binary[10] = {1,2,0,3,4,5,6,7,8,0};
	B b(binary, 10);
	return b;
}

int main(int argc, const char *argv[])
{
	A a = ReturnB();
	int len = a.datalen;
	std::cout << "This should return 10 and it returns " << len << "\r\n";
	return 0;
}



[Updated on: Sun, 09 February 2020 14:44]

Report message to a moderator

Re: Big issue with Visual Studio 2019 (some versions) [message #53019 is a reply to message #53011] Sun, 09 February 2020 14:35 Go to previous messageGo to next message
Alboni is currently offline  Alboni
Messages: 191
Registered: January 2012
Location: Deventer, Netherlands
Experienced Member
An interesting thing happens:

if I make the following change:
// 		A(B& b);
		A(const B& b);

Then the warning goes away and I get the correct results...... Confused

That also works for String::String(StringBuffer&) but that one can't be const of course.

[Updated on: Sun, 09 February 2020 15:22]

Report message to a moderator

Re: Big issue with Visual Studio 2019 (some versions) [message #53020 is a reply to message #53018] Mon, 10 February 2020 10:32 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12179
Registered: November 2005
Ultimate Member
Sorry, but way too long. Have a pity for those poor compiler maintainers... Smile

Does this show the problem?

#include <iostream>

struct B;

struct A {
	A(char*) { std::cout << "A::A(char *)\n"; }
	A(B&)    { std::cout << "A::A(B&)\n"; }
};

struct B {
	operator char*() { std::cout << "B::operator char *()\n"; }
};

A Test()
{
	B b;
	return b;
}

int main(int argc, const char *argv[])
{
	A a = Test();
	return 0;
}
Re: Big issue with Visual Studio 2019 (some versions) [message #53021 is a reply to message #53011] Mon, 10 February 2020 10:58 Go to previous messageGo to next message
Alboni is currently offline  Alboni
Messages: 191
Registered: January 2012
Location: Deventer, Netherlands
Experienced Member
Yes, it does. Excellent pruning Very Happy But it needs to return a value to compile:

//	operator char*() { std::cout << "B::operator char *()\n"; }
	operator char*() { std::cout << "B::operator char *()\n";  return ""; }


Re: Big issue with Visual Studio 2019 (some versions) [message #53022 is a reply to message #53021] Mon, 10 February 2020 11:50 Go to previous message
mirek is currently offline  mirek
Messages: 12179
Registered: November 2005
Ultimate Member
https://developercommunity.visualstudio.com/content/problem/ 912723/recent-version-of-visual-c-compiler-might-have-ove.ht ml
Previous Topic: Problem linking using RegExp
Next Topic: Possible inconsistency with Rect::Contains() right-bottom bounds?
Goto Forum:
  


Current Time: Mon Feb 17 08:32:30 CET 2020

Total time taken to generate the page: 0.00924 seconds