Home » Community » U++ community news and announcements » 2022(?).2 beta
|
|
|
|
|
|
| Re: 2022(?).2 beta [message #59343 is a reply to message #59326] |
Sun, 18 December 2022 05:07   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
Hi Mirek:
I understand that U++ currently aims to be compliant with c++14. Overall, U++ is very close to c++20 compliant.
IIRC, the only kind of complaints gcc/clang make when building TheIDE with std=c++20 is about caputuring `this` by default is deprecated in c++20 for a lambda. I am not sure if changing affected code to get rid of all such warnings will affect c++14 compliance but it's easy to make both worlds(or maybe all 3 worlds if we want to refer to c++17 and c++20 separately) happy anyways.
With MSVC, it is a different story. It complains in many cases like
return some_condition ? SomeString : "Some ASCIIZ String";
These, though tedious, are easy to fix. I am no language lawyer, cannot tell which of MSVC and GCC/CLANG is/are correct here. But MSVC changes its behaviour from accepting it in C++14 to rejecting it in C++17 and beyond may tell something. Anyway it's not hard to make all worlds happy by just a little bit more keystrokes.
There are some more errors when compiling TheIDE with MSVC (mine is MSBT 2019 I believe) and std set to C++20. Another one is caused by Upp::Moveable::AssertMovealbe0 or something like that.
I mainly use CLANG now but I feel more assured if my code compiles fine on Ubuntu with GCC & CLANG, and on Windows with MS c++ compiler. I don't know if other users think this kind of check has some value, but it likely will be welcomed if a user can use u++ with more recent standard if he/she wishes(so that he/she can embrace utilities like constexpr-if and concept), and with the compiler he/she choose (one of the 3 major), while the bulk of U++ is in c++14 and be backward compatible.
Correction and some detailed error message:
1. The MSVC I used is MSBT22x64
2. The error message with AssertMoveable0 is like
Quote:
C:\upp\uppsrc\Core\Topt.h (157): error C2100: illegal indirection
C:\upp\uppsrc\Core\Topt.h (172): note: see reference to function template instantiation 'void Upp::AssertMoveable0<T>(T *)' being compiled
with
[
T=double
]ChWin32.cpp
BR,
Lance
[Updated on: Sun, 18 December 2022 05:59] Report message to a moderator
|
|
|
|
|
|
| Re: 2022(?).2 beta [message #59346 is a reply to message #59344] |
Sun, 18 December 2022 14:48   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
Hi Mirek:
Thank you for your attention to this matter.
The following macro will perfectly pacify both GCC and CLANG.
#if __cplusplus > 201703L
# define CAPTURETHISBYVALUE ,this
#else
# define CAPTURETHISBYVALUE
#endif
And when using it
void ColorWindow::Paint(Draw& draw)
{
auto f = [= CAPTURETHISBYVALUE]{ auto v = GetData(); };
draw.DrawRect(GetSize(), White());
auto v = f();
...
}
It should be easy to add support for MSVC similarly too.
This way, we only care that the U++ library can compiles with std=c++14, std=c++17, std=c++20 or later std. Whether a u++ library user decide to follow the practice so that his/her code is also multiple c++ standards compatible, or simply choose one of the standard to embrace, is not a concern of u++ library developers (like you and Klugier).
The philosophy here is: u++ can choose a stable and well supported c++ standard to embrace, but it should not limit or discourage its users from trying later standard. IMHO, comparing to package-wise c++ standard selection options(it will certainly confuse assist++ if at all doable), this kind of fix in the U++ library level is less painful.
BR,
Lance
PS:
Or probably even easier.
#if __cplusplus > 201703L
# define CAPBYVALUETHIS =,this
#else
# define CAPBYVALUETHIS =
#endif
Then do a find in files and replace from uppsrc root, it's almost done. I figure there are <=2 occassioins where [=] are not within a member function thus [=,this] is invalid which need be fixed after the find and replace.
[Updated on: Sun, 18 December 2022 15:30] Report message to a moderator
|
|
|
|
|
|
|
|
| Re: 2022(?).2 beta [message #59349 is a reply to message #59347] |
Sun, 18 December 2022 18:50   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
Klugier wrote on Sun, 18 December 2022 09:41Hello Lance,
Quick question, what about replacing [=] with [this]. Does it produce warning with C++20? It compiles fine with C++14 and I think in most cases we can replace it. We are using [=] to capture local variables very really, however this can be overcome by explicit argument capture.
The solution with CAPTURETHISBYVALUE is ugly and very impractical especially for U++ maintainers 
I agree that we should be compatible with C++20 as much as we can. On the other hand, I also think it is a good moment to change default standard from c++14 to c++17. c++14 is 8/9 years old standard and on most of currently supported system compilers with c++17 support are present. For example I like auto [x, error] = GetTuple() that can not be used in c++14 word. Very useful feature when you want to back-propagate error without using exceptions. I remember, we discussed this transition some time ago, but maybe it is good to discuss it one more time 
Klugier
Hi Klugier:
Unfortunately it doesn't work. In a lot of occassions [=] captures more than just [this].
I will try my approach and report the result.
Regards,
Lance
PS:
It works perfectly in GCC/CLANG on Ubuntu.
Here is what I did:
1. Insert the definition of CAP_BY_VALUE_WITH_THIS after #include <utility>
#if __cplusplus > 201703L
# define CAP_BY_VALUE_WITH_THIS = ,this
#else
# define CAP_BY_VALUE_WITH_THIS =
#endif
2. Do a Replace in Files..., replace all occurrences of [=] with CAP_BY_VALUE_WITH_THIS, for all files under the folder uppsrc;
3. Compile some examples, eg. <Examples/Color>, fix all errors due to wrongful replacement in step 2. I believe there are 3-4 such occurrences.
4. Compile TheIDE, 2 more errors pop up. In <ide/Builders/Install.cpp>, replace
auto Fix = [CAP_BY_VALUE_WITH_THIS](const char *s) {
with
auto Fix = [=](const char *s) {
And in <ide/Designers/HexView.cpp>, Ln 98, replace
RegisterGlobalSerialize("FileHexViewPos", [CAP_BY_VALUE_WITH_THIS](Stream& s) {
with
RegisterGlobalSerialize("FileHexViewPos", [=](Stream& s) {
and ide is ready to be built. Of course I fix problems as GCC complains to me. As I did nothing in between, any errors that stopped compiling would mean I need to replace [CAP_BY_VALUE_WITH_THIS] with [=] (where there is no `this` at all).
BR,
Lance
[Updated on: Sun, 18 December 2022 20:21] Report message to a moderator
|
|
|
|
| Re: 2022(?).2 beta [message #59350 is a reply to message #59249] |
Sun, 18 December 2022 19:46   |
mr_ped
Messages: 826 Registered: November 2005 Location: Czech Republic - Praha
|
Experienced Contributor |
|
|
@Mirek: BTW, how about IDE: closing window moves it in Ctrl+Tab order after all opened documents.
I think we did discuss this few years back, and it was like by-design for you? But it keeps irritate me even after those years: I switch by Ctrl+Tab to file which I want to close, Ctrl+W to close it, and now I want to move to some other open file and hit Ctrl+Tab, and closed file is back... I'm just not used to this, and I don't see value in it, feels like wrong UX to me.
I can try to do pull request if you don't mind the change.
BTW you seem to mostly apply pull requests manually, but that way you make the contribution in git changed to your user, not sure if this is intentional, or just the way how you use git.
And one more very minor IDE bug/quirk: when I Ctrl+M to select main package, open one, it re-opens all tabs which were open during working on that package = nice. But current state seems to be saved only when leaving IDE, not when I do another Ctrl+M and switch to other package. That's IMHO unexpected UX, if the state loads upon Ctrl+M, it should also save updated state of open tabs on it?
(sorry if these requests are out of scope for 2022.3, but as I'm lately using IDE daily, I'm pressing the stuff which nags me )
|
|
|
|
| Re: 2022(?).2 beta [message #59351 is a reply to message #59350] |
Sun, 18 December 2022 19:53   |
 |
mirek
Messages: 14291 Registered: November 2005
|
Ultimate Member |
|
|
mr_ped wrote on Sun, 18 December 2022 19:46@Mirek: BTW, how about IDE: closing window moves it in Ctrl+Tab order after all opened documents.
I think we did discuss this few years back, and it was like by-design for you? But it keeps irritate me even after those years: I switch by Ctrl+Tab to file which I want to close, Ctrl+W to close it, and now I want to move to some other open file and hit Ctrl+Tab, and closed file is back... I'm just not used to this, and I don't see value in it, feels like wrong UX to me.
I can try to do pull request if you don't mind the change.
BTW you seem to mostly apply pull requests manually, but that way you make the contribution in git changed to your user, not sure if this is intentional, or just the way how you use git.
And one more very minor IDE bug/quirk: when I Ctrl+M to select main package, open one, it re-opens all tabs which were open during working on that package = nice. But current state seems to be saved only when leaving IDE, not when I do another Ctrl+M and switch to other package. That's IMHO unexpected UX, if the state loads upon Ctrl+M, it should also save updated state of open tabs on it?
(sorry if these requests are out of scope for 2022.3, but as I'm lately using IDE daily, I'm pressing the stuff which nags me )
OK, if rc1 fails, I will look into this
|
|
|
|
|
|
| Re: 2022(?).2 beta [message #59354 is a reply to message #59352] |
Sun, 18 December 2022 20:08   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
mirek wrote on Sun, 18 December 2022 13:55Lance wrote on Sun, 18 December 2022 14:48
#if __cplusplus > 201703L
# define CAPTURETHISBYVALUE ,this
#else
# define CAPTURETHISBYVALUE
#endif
It does not feel nicer than disabling the warning...
Mirek
Hi Mirek:
It doesn't. But this technique is widely used in standard library implementations. It's a necessary evil (if not in this particular situation where you can opt to turn off warnings).
For example, many std::vector member functions are now constexpr modified, what's a better way to provide cross-c++-standard support in this situation? I am not sure if there is one, but the one in practice is a MACRO that will vanish in a lower language/library standard.
BTW, there is no guarantee it will not be promoted to an error in some later days when U++ probably is in c++17. So chance is the problem is merely deferred instead of being solved by disabling warnings on it.
BR,
Lance
[Updated on: Sun, 18 December 2022 20:25] Report message to a moderator
|
|
|
|
| Re: 2022(?).2 beta [message #59355 is a reply to message #59354] |
Sun, 18 December 2022 21:54   |
 |
Klugier
Messages: 1117 Registered: September 2012 Location: Poland, Kraków
|
Senior Contributor |
|
|
Hello Mirek and Lance,
I agree with Lance that someday capture this by [=] might be compilation error instead of warning. Such precedence happened in the past. For example in C++17 std::auto_ptr had been removed. However for capturing this by [=], I do not see that it will be removed in C++23. So, disabling warning might give us 3-4 additional years...
In accordance to table on nextptr article the only valid capture this that works with all standards is capture this as [this] and [&]:

As, in my previous post, we should follow that approach. It won't be easy, but doable for our code base within 1-2 days. Whenever, we need to pass additional variable it should be pass explicitly [this, x] etc.. Alternatively, we can convert [=] to [&] as it is valid too. However, it might caused some unwanted bugs...
Using global macro is not an option to me as I wrote in my previous post.
Klugier
-
Attachment: Table.png
(Size: 76.41KB, Downloaded 533 times)
U++ - one framework to rule them all.
[Updated on: Sun, 18 December 2022 21:59] Report message to a moderator
|
|
|
|
|
|
| Re: 2022(?).2 beta [message #59357 is a reply to message #59355] |
Sun, 18 December 2022 22:35   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
Hello Klugier,
I can confirm that all U++ currently uses are [=].
Out of which, some(I expect it to be a total of less than 10) need to remain as [=] prior or beyond c++20; while the majority rest can be changed to [=,this] to make the code compliant to c++20 (which, unfortunately will displease prior c++20 world).
I cannot really tell how many out of the second lot can be replaced by [this] without creating noise when they need more than just `this`, eg, also capturing some local variables, etc.
Do you mean to differentiate from the second lot the ones that actually require some other variables, and list each of them manually so that prior and beyond c++20 worlds will be happy with their capture lists?
It certainly is doable, but it might be a bit too much effort, IMHO, just for the sake of avoiding an unwanted MACRO.
Otherwise the quickest & dirtiest solution is to change all [=] to [&], with possibly undesired side-effects.
It's totally up to you and Mirek though. We will be happy with a standard-tolerant U++ library however achieved
BR,
Lance
[Updated on: Sun, 18 December 2022 23:08] Report message to a moderator
|
|
|
|
|
|
|
|
| Re: 2022(?).2 beta [message #59360 is a reply to message #59359] |
Sun, 18 December 2022 23:14   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
mdelfede wrote on Sun, 18 December 2022 17:03I was the one adding Astyle *many* years ago... and it's true that it has not been updated since years.
But, IMHO, a tool to format code is quite useful. I still use it, even if it's broken on new code.
Ok for removing, but also ok for adding a new one.
Hi mdelfede:
Astyle's last activity is probably a few years old. Like I mentioned before, formatting code with bitfields with the old formatting utility is a disaster. It takes a lot of work to bring bitfields in order every time one formats <CtrlCore/CtrlCore.h>. bitfields is something c++ inherited from old c, present since day 1 of the language. It's surprising that this actually happened.
Go with the big guy, here llvm-org/LibFormat, is a more future proof decision.
BR,
Lance
[Updated on: Sun, 18 December 2022 23:19] Report message to a moderator
|
|
|
|
|
|
| Re: 2022(?).2 beta [message #59362 is a reply to message #59360] |
Sun, 18 December 2022 23:35   |
 |
Klugier
Messages: 1117 Registered: September 2012 Location: Poland, Kraków
|
Senior Contributor |
|
|
Hello,
It looks like that in this thread we are talking about lot of things Backing to Mireks attention about lack of clang-format in our toolchaing on Windows. This executable can be downloaded from muttleyxd/clang-tools-static-binaries GitHub repository. On Windows when we will make decision to integrate this tool, we can put it under bin/clang-format directory or attached to bin/clang/bin/*.
Klugier
U++ - one framework to rule them all.
[Updated on: Sun, 18 December 2022 23:35] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: 2022(?).2 beta [message #59378 is a reply to message #59350] |
Mon, 19 December 2022 12:20   |
 |
mirek
Messages: 14291 Registered: November 2005
|
Ultimate Member |
|
|
mr_ped wrote on Sun, 18 December 2022 19:46@Mirek: BTW, how about IDE: closing window moves it in Ctrl+Tab order after all opened documents.
I think we did discuss this few years back, and it was like by-design for you? But it keeps irritate me even after those years: I switch by Ctrl+Tab to file which I want to close, Ctrl+W to close it, and now I want to move to some other open file and hit Ctrl+Tab, and closed file is back... I'm just not used to this, and I don't see value in it, feels like wrong UX to me.
I can try to do pull request if you don't mind the change.
BTW you seem to mostly apply pull requests manually, but that way you make the contribution in git changed to your user, not sure if this is intentional, or just the way how you use git.
Hopefully fixed.
|
|
|
|
| Re: 2022(?).2 beta [message #59382 is a reply to message #59373] |
Mon, 19 December 2022 18:43   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
mirek wrote on Mon, 19 December 2022 04:08Lance wrote on Mon, 19 December 2022 00:41Hello Mirek and Klugier:
The following code is an excerpt from /usr/include/c++/11/bits/stl_vector.h
iterator
begin() _GLIBCXX_NOEXCEPT
{ return iterator(this->_M_impl._M_start); }
/**
* Returns a read-only (constant) iterator that points to the
* first element in the %vector. Iteration is done in ordinary
* element order.
*/
const_iterator
begin() const _GLIBCXX_NOEXCEPT
{ return const_iterator(this->_M_impl._M_start); }
/**
* Returns a read/write iterator that points one past the last
* element in the %vector. Iteration is done in ordinary
* element order.
*/
iterator
end() _GLIBCXX_NOEXCEPT
{ return iterator(this->_M_impl._M_finish); }
Without looking into the definition of _GLIBCXX_NOEXCEPT, most experienced c++ users(, all participants of this thread for sure,) can tell that it will expand to noexcept when the -std version supports it and vanishes otherwise.
It might not be pleasant or pretty, but it certainly works and can be argued as the most reasonable solution in this particular situation.
It's a common problem that libraries with some history need to support different versions; maintaining backward compatibility should not mean stay backward. U++ necessarily has done similar thing for similar purposes, I believe.
Why is it so hard to swallow in this particular case?
BR,
Lance
Uhm, I guess we are presented with 2 more or less equivalently ugly options here. One of them requires a significant amount of work....
Hello Mirek and Klugier:
Another drawback for the disable-warnings option: Like Novo said, he and many similar-minded people are still using very old systems/compilers; people are different. What if in 4 years' horizon you decide that time has mature for switching to c++20 but there are still a significant number of users who wish to be able to have c++14 as an option?
From the point of smoother user experience, I am not quite sure if it's a good idea that the mainstream version today will become completely unusable the next day because it's upgraded. You likely need to deprecate it and keep it going for a couple of more years so people have time to transit to the new mainstream version/standard.
If this will be the case, we end up still need to be able to support both c++14 and c++20 at the same time for at least a period of time: trouble is deferred instead of solved. And as times goes, more [=] cases will be added to U++ (not in a significant number, but it's a non-decreasing function of time), chance is it will take more time and effort at the postponed switch date.
BR,
Lance
[Updated on: Mon, 19 December 2022 18:49] Report message to a moderator
|
|
|
|
| Re: 2022(?).2 beta [message #59383 is a reply to message #59382] |
Mon, 19 December 2022 19:10   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
And some of the viable options if multi-c++-version support is a necessity (as proposed by Klugier and me):
1. [=] to [&] when necessary. Make local copies of variables that are originally captured by value with undesired modification, and refer only to the copy in the lambda body. A fictitious example:
void ClassName::FunctionName()
{
int i = 0;
auto f = [=]{ this->DoSomething(); ++i; };
....
}
should be rewrite to
void ClassName::FunctionName()
{
int i = 0;
int j = i;
auto f = [&]{ this->DoSomething(); ++j; };
....
}
pros: concise capture list; no unwanted GLOBAL MACRO;
cons: it's time consuming and error-prone for the change. Majority of affected lambda bodys need to be analysed individually to make copy& refer only to copy manually for affected variables. You get no help from the compiler. If you miss changing one of the reference to old variable name, or miss to change one of the variable you don't want to be modified, a bug arise. And it could be subtle to discover and fix all the errors. And there is no mechanism to enforce the rule, developers/maintainers (mainly both of you atm) has to watch out and be disciplined;
option 2: list individual variable in the capture list.
Pro and cons are quite similar to option 1. Less chance of subtle bugs. Potentially long and tedious capture list.
option 3: MACRO
pros: clean, fast, standard practice. Other u++ users can choose to use the MACRO in their own code to smoothen future transition form c++14 to c++20.
cons: both of you abhor the MACRO that needs to be introduced. come on guys, if it's just because you don't like the name, feel free to choose a better one.
Or shall we start a poll-like thing so that more input can be received? I particularly are interested to hear what @Oblivion and @Koldo have to say on this topic.
[Updated on: Mon, 19 December 2022 19:42] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
| Re: 2022(?).2 beta [message #59390 is a reply to message #59389] |
Mon, 19 December 2022 23:54   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
mirek wrote on Mon, 19 December 2022 17:35Lance wrote on Mon, 19 December 2022 23:14mirek wrote on Mon, 19 December 2022 14:22Lance wrote on Mon, 19 December 2022 19:10And some of the viable options if multi-c++-version support is a necessity (as proposed by Klugier and me):
1. [=] to [&] when necessary. Make local copies of variables that are originally captured by value with undesired modification, and refer only to the copy in the lambda body. A fictitious example:
[&] does not help and the problem is not local copies.
This does not work:
struct MyApp : TopWindow {
Button b;
MyApp() {
int j = 12;
b << [&] { PromptOK(AsString(j)); };
}
};
I see. Reference to local variables invalidated out of function body. So this option is eliminated. We are left with only 2.
3. Disable warning and hope that it will be deprecated for really long time. I bet it will.
See, this whole thing is rather unfortunate. There are 3 options, none of them really good. 2 of these require significant work and a chance of introducing new bugs....
1. Disable warnings option: almost effortless. but like I mentioned in a previous post, when you eventually decide to move to c++20, everybody else need to move with you overnight, or otherwise there will be the same problem of supporting pre- & post-c++20 world simultaneously. I am fine with that but not sure if other people will like it.
2. Klugier's other proposal ([this, a,b,c]). Heavy work, chance of bugs.
3. My proposal. Majority work can be done in 20 minutes. Other examples or packages, etc can be left until a bug is reported (mainly in the case old [=] doesn't involve a `this`, just change back to [=], can be fixed without thinking). I don't expect other subtle bug be introduce because of this approach. And it should settle down in a time span of months, but involves little work on maintainers/users' part after the initial 20 minutes or so.
In a previous post, I have listed procedures I took. Replace in files, then compiler will tell the case where original [=] doesn't involves `this`, in which cases we change them back to [=]. I fail to see any chance a subtle bug will be introduced as they mean exactly same thing, just added compliance to c++20.
BR,
Lance
PS: you probably understand my approach fully. but let me explain it once more.
Context:
we have around 120ish [=] lambda capture in u++ source tree, majority of which should be changed to [=,this] from c++20 onwards. Unfortunately [=,this] is not valid pre-c++20. We want a way to make both worlds happy.
Conditional Macro: one apparent approach is to use a macro that expands to [=] with std = pre-c++20 and [=, this] when std>=c++20. If we do it properly, no bug will be introduced because of this: they are functionally equivalent.
Now suppose we have such a macro named MY_MACRO, which will be expanded to = or =,this, depending on c++ standard used.
Recommended Procedure
1. Do "Replace in Files" for all files under $UPPSRC, replace all occurences of [=] with [MY_MARCO]
2. Open a less involving package to fix the cases where no `this` were captured originally. The one I used is <examples/Color>. F7 to compile it, with -std=c++20, preferably in debug mode to save time. There will be like 3-4 cases where we have wrongfully replaced [=] with [=,this], locate them, change back to [=]. Now the bulk of jobs are done;
3. Open package `theide`, do the same thing as in step 2. We will encounter 2 other cases where we have wrongfully made the replacement. Fix them, theide will compile fine;
4. We can do a buildall on the u++ src tree(I remember we have something like that), then we can fix all such wrongful replacements at once. Or we can leave it until it's be compiled and reported by users.
5. We have a clean uppsrc that's c++-version-smart on existing lambda captures.
[Updated on: Tue, 20 December 2022 00:38] Report message to a moderator
|
|
|
|
|
|
| Re: 2022(?).2 beta [message #59392 is a reply to message #59391] |
Tue, 20 December 2022 00:48  |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
Novo wrote on Mon, 19 December 2022 18:19Lance wrote on Mon, 19 December 2022 12:43
Like Novo said, he and many similar-minded people are still using very old systems/compilers;
Systems I mentioned are not "very old".
Void Linux is a rolling distro (that means that you get latest versions of everything except of core packages like Clang). This is done for stability. I personally spent quite a lot of time dealing with bugs in compilers (code generators). And because of that I prefer to use a stable and well tested compiler even if it seems to be outdated.
Void Linux is ranked number five by DistroWatch.
Netflix runs on FreeBSD.
Almost all gaming consoles run FreeBSD.
So "very old systems/compilers" aren't that old 
ok, they are not that old.
My point is, say, one day, Mirek decides c++20 is stable enough to switch to, and c++14 support will be abandoned at the same time. Do you expect you undoubtedly have the same judgement on the stability of c++20? And you will be ready to make the move simultaneously? If your answers to both questions are yes and significantly most users also agree, then disable-warning is the surest way to take.
|
|
|
|
Goto Forum:
Current Time: Mon May 04 06:00:16 GMT+2 2026
Total time taken to generate the page: 0.01775 seconds
|