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: 198
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: 198
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: 12616
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: 198
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: 198
Registered: January 2012
Location: Deventer, Netherlands
Experienced Member
index.php?t=getfile&id=5988&private=0
  • Attachment: vstudio.png
    (Size: 28.06KB, Downloaded 252 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: 198
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: 12616
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: 198
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: 198
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: 12616
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: 198
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 messageGo to next message
mirek is currently offline  mirek
Messages: 12616
Registered: November 2005
Ultimate Member
https://developercommunity.visualstudio.com/content/problem/ 912723/recent-version-of-visual-c-compiler-might-have-ove.ht ml
Re: Big issue with Visual Studio 2019 (some versions) [message #54473 is a reply to message #53011] Tue, 28 July 2020 18:12 Go to previous messageGo to next message
gocubsgo
Messages: 1
Registered: July 2020
Junior Member
Is there any update on this? It seems like Microsoft never did respond to your feedback?

With the latest Visual Studio 2019 (16.6.5) I'm still getting many C4927 warnings. The result in my app is the UI (all defaults) is missing elements, like some assets aren't being loaded. Forcing to the older Platform Toolset (v141) when building upp results in things looking as they should.

By the way, this is using the 2020.1 release. Looking at the latest nightly, I don't see anything suggesting it would be different in this respect.
Re: Big issue with Visual Studio 2019 (some versions) [message #54474 is a reply to message #54473] Wed, 29 July 2020 10:32 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12616
Registered: November 2005
Ultimate Member
gocubsgo wrote on Tue, 28 July 2020 18:12
Is there any update on this? It seems like Microsoft never did respond to your feedback?

With the latest Visual Studio 2019 (16.6.5) I'm still getting many C4927 warnings. The result in my app is the UI (all defaults) is missing elements, like some assets aren't being loaded. Forcing to the older Platform Toolset (v141) when building upp results in things looking as they should.

By the way, this is using the 2020.1 release. Looking at the latest nightly, I don't see anything suggesting it would be different in this respect.


No update. This is clearly Visual C++ bug and current compiler is broken.

Fortunately Windons CLANG is now good enough as replacement (which works out of box).

Mirek
Re: Big issue with Visual Studio 2019 (some versions) [message #54483 is a reply to message #53011] Wed, 29 July 2020 14:17 Go to previous messageGo to next message
Alboni is currently offline  Alboni
Messages: 198
Registered: January 2012
Location: Deventer, Netherlands
Experienced Member
I can't use clang or mingw on windows because it misses certain libraries that I need like winscard and plugin/wav also doesn't compile on either.
However I find applying the workaround* relatively easy and I don't upgrade all that often anyway, so I'll see when it happens and if not, no big deal. Just have to be mindful of that compiler quirk.

* workaround is putting
return String(s);
instead of
return s;
everywhere the warning throws.

[Updated on: Wed, 29 July 2020 14:34]

Report message to a moderator

Re: Big issue with Visual Studio 2019 (some versions) [message #54484 is a reply to message #53011] Wed, 29 July 2020 14:27 Go to previous message
Alboni is currently offline  Alboni
Messages: 198
Registered: January 2012
Location: Deventer, Netherlands
Experienced Member
It would however be handy if this patch could be made:
cppbuilder.cpp line 469

before:
	if(package == mainpackage)
		info << Join(SvnInfo(package), "\r\n");

after patch
	if(package == mainpackage)
		info << Join(SvnInfo(package), "\r\n") << "\r\n";

This is because I am including "build_info.h" in the .rc file and the microsoft resource compiler throws an error if the last line of an included file does not end on a \r\n. Yeah, also their fault but it's an ancient bug that will likely never be fixed.
It would avoid me having to recompile theide on a broken system.

[Updated on: Wed, 29 July 2020 14:30]

Report message to a moderator

Previous Topic: Warning in Log.cpp
Next Topic: Add compilable testcases for nontrivial problems!
Goto Forum:
  


Current Time: Wed Aug 12 05:37:11 CEST 2020

Total time taken to generate the page: 0.01391 seconds