|
|
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  |
 |
Alboni
Messages: 216 Registered: January 2012 Location: Kajaani, Finland
|
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 #53018 is a reply to message #53011] |
Sun, 09 February 2020 14:33   |
 |
Alboni
Messages: 216 Registered: January 2012 Location: Kajaani, Finland
|
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 #54473 is a reply to message #53011] |
Tue, 28 July 2020 18:12   |
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 #54483 is a reply to message #53011] |
Wed, 29 July 2020 14:17   |
 |
Alboni
Messages: 216 Registered: January 2012 Location: Kajaani, Finland
|
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 instead of 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   |
 |
Alboni
Messages: 216 Registered: January 2012 Location: Kajaani, Finland
|
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
|
|
|
|
|
|
|
Goto Forum:
Current Time: Sun May 11 12:03:44 CEST 2025
Total time taken to generate the page: 0.00462 seconds
|
|
|