 I'll cover warnings and diagnostic stuff and then Jakub will cover new optimization for 5 and C++ 17 and stuff like that. A couple of points before I dive into those new warnings, I'm not gonna cover all of those new warnings because some of them I don't really know all that well and some of them are those ones that I don't like very much so this is not a complete list for the complete list. Please see the GCC page and there should be changes page where you can see all those new stuff. Another thing is that this is gonna be only about C and C++ because I don't really know any other language and we don't generally care about FORTRAN that much so sorry if any of you like FORTRAN or ADA or GOAD and this is not gonna be too interesting for you I suppose. Anyway, some of those new warnings will be enabled by default, some of them you need to enable by WOL or WXTRA and some of them you'll have to enable specifically so don't be surprised if you don't see them very much because some of them have too many false positives or have some certain problems that are too hard to fix so you'll have to enable them specifically. Now I'm sure that not all of you will like those new warnings maybe you'll hate some of them maybe you even hate those warnings I wrote which I won't take personally but if you if you it's okay if you don't like it that's fine you can either turn the warning warning off completely by using dash w no and some stuff or you can also use like GCC I mean pragma GCC diagnostics and you can you can disable the warning for like just a block of code or a function but if you do find something that bums you out please do open PR because sometimes we even fix things so please don't don't be afraid we need those supports I really really appreciate them well so the first warning is probably the most controversial one actually when I first posted a page for this warning the reaction was this is purely evil and that was really encouraging but anyway over time I fixed a lot of stuff and and this warning is now in so it weren't about switches when one case falls down to another like on this test case it's clearly about that the case one falls down falls through to case two and the warning would warn so it would it should be able to catch mistakes like that but for the warning to be really useful it needs to handle various control flow statements such as ifs so nice so it handles if else chains so it's the warning is able to figure out that you I mean the first branch cannot really fall through because because of this break but the second branch can actually fall through down to case two but the third branch cannot fall through so it would say like it can fall through from this point down to case two so it should be quite clever on the other hand there are some stuff that it's really hard to handle I mean like sometimes it's hard to to gauge whether a loop can terminate or not because this is our compile stuff so so it's not foolproof now of course sometimes you actually want the fall through to happen and in that case you need to say to a compiler that you really meant it like think of Duff's devices where you rely on the fall through all the way down depending on some size and in such case you can in C use a new statement with an attribute and it's the attribute is fall through so the compiler won't warn now in C++ you can use in C++ 11 you can use the square thing attribute stuff which is in standard C++ 11 and standard C++ 7 17 says that it's actually standardized so the fall through in square brackets is is standard thing so if you can please use that if you cannot and you can use the attribute or you can use a fall through command which is something we had to discuss a lot and you don't want to know you don't want to know I mean I mean this is insane so well I mean because this fall through is nice but then some some other projects use this or this or this or whatever else and it's really never-ending so we decide yeah yep yep because we cannot offer to do like syntactic analysis so if it's no way it's I mean we could but now because some people complain like okay but this is just English so what if I write it in French and whatever and and it's just impossible to handle all of that so we decided well actually it's Jacob's idea and we have five levels of the of the fall through warning and I think the level one just accepts any comments if it sees a comment then it assumes that before a case I mean then it assumes that it's a fall through command but on the other hand if you use like the level four then it only accepts like I think the first one or something just a just a few just a few of them otherwise there's yeah yeah because because yeah some people wanted it that way default is three three yeah it's a you would have to yeah and it could be a and it handles to spelling so through so we can be like through it oh you or just you know that's a good a good point yeah but I'd like to point out that this warning is only enabled by W extra so so not all packages will actually come across this warning but but I mean I didn't further I'm asking about and it wasn't so bad actually you know a lot of packaged fail because of that but it was less than I thought it would be for the comments yeah yeah speaking of bugs like I told you we handle control flow statements I kind of lied because we don't handle nested switches something I was reluctant to do but I think I will have to do it probably before we release the GC7 so it should handle nested switches to but no promises well W pointer compares another baby of pine which I don't really like the name of it but it's too late to change the name and it's pretty simply just warrants if you compare a pointer with a zero character constant or zero character in C++ if you want it's basically means that you it's likely that you forget to the reference P here or it usually typically P is an array and you forget to use square brackets and the element number yeah I mean why would you why would you use zero character constant instead of now I mean you could but it's weird and actually this code is invalid in C++ 11 for the reason it's as you can see so so many package will fail because of this too now duplicated branches is I think useful warning because I made it but it's it warrants if you have identical branches as you can see it really makes no sense to to have this condition if this is correct that these two are same then it doesn't make to really have the conditional so you can just use return x plus 3 and it also handles conditional operators too so so it really doesn't make much sense I think now there is some problem with macros I won't really go into any details but if you use a lot of macros then it can have some false positives so you'll have to enable it specifically W restrict is warrants when you break the assumption that restrict well it qualified parameter aliases with another argument so in this case you have food that takes to restrict qualified pointers but actually you pass them the same address which is which is which invalid because because the compiler could optimize out a lot of stuff and it could misbehave so that's not a warning I didn't make this time W aloka larger than n is if you want to find unbounded aloka uses or or aloka alokas that might use too large argument because as you know aloka just moves the stack pointer so if you use alok of it to huge argument it could smash your stack or whatever so we have an option for that now and so in this case if you if you use the limit 500 the compiler would warn because it can see that can figure out that in this code path you could call alaka with like 600 or something so it would warn and if you don't have this this condition at all it would want to probably so it can it can find a lot of bugs and the same option exists for a variable length raise to it's just W VLA larger than and then there's W aloka 0 that warrants if you call aloka with with 0 and then there's W aloka that warrants for any aloka then too bad then we cannot know I think no optimization is apparently able to but if it can figure out then it would warn depend yeah well it's really about if you can hit a code path with aloka and you the compiler can prove that it can have argument over the limit as you specified and it would warn if there is a path that leads to alaka colon should warn the blue yeah that right right yeah it's pretty much the same but I probably should have made a slide about it but I didn't but it's the same thing basically well another thing is W memset outside switch warrants for memset calls if the first argument is an array this is a here and a of an element but the third argument is actually the number of elements but not the size of this array which is clearly a bug yeah yeah of course it int could be probably whatever but but in this case it is probably a bug so the compiler would warn and you you should use size of and the the size of an element of the array no I don't think so because it's W memset so I suppose it's not for a man move or I don't think so I think it's just memset so far I but maybe it could be a good idea actually element it I didn't name it it could be I don't know why it's not element you know okay sorry another warning is W in blue context which would warn about suspicious uses of integer values in brilliant context so in this case it's so in this conditional it probably the conditional doesn't really make sense because it will ever evaluate to true every time and I don't think that's what you want so the compiler is able to warn in in these situations W switch unreachable warrants if you if you have executable code between switch between switches controlling statement which is just count and between the first case clearly the assignment here will never be executed so the compiler will warn but I need to point out that you can still have declarations here that would work the warning wouldn't warn it's it's it's valid to have declarations here just not initializer or assignment or any any other code it will never be executed so the compiler will warn and we also worked on diagnostics so the compiler will be able to offer more fixed hints it will say basically maybe you meant to write something like this and it will provide you the actual code so in IDs like Eclipse it will be able to fix it basically automatically if you allow it to and it's also now able to to give a hint about if you misspell function names so apparently we have declaration of foobar but we used foobar with an underline so it would it will say if you did you mean this instead of this so that's pretty cool and it also handles like macro names and handles some other stuff basically but yes yeah yeah and there's an option that can that is diagnostics can automatically emit a patch so it's for IDs I don't I've never tried it but it's there's this option now I think it is yeah could place now so here we go okay so one of the major new features in GCC 7 is almost complete support for C++ 17 which is still moving because yeah while C++ moved to those three years distance between releases there is still one at least at least one C++ meeting now in February which is going to vote some minor changes into the standard again before it's going to be approved hopefully so GCC 7 right now implements all the core features of C++ 17 as the first compiler but of course some new features can can get in and we will have to either implement them or put it in 7.2 or something and on the library side we have almost all features there we have a web page which lists the features implemented and GCC versions which which were the first to implement them and on the library side you will see a couple of small issues not implemented yet from the majors major major changes which are still missing is that the file system library is still available as as a TR in GCC 7 and not not as the part of the official standard so it's not in STDs in namespace but it's it's TR so it's also not in lib std c++ so yet it's it's a separate library which you link and it's a only it's still not not completely a bi stable it can change so from I would like to just point out a couple of of recently implemented changes which were not in GCC 6 one of them is structured structured bindings which allow you to split a tuple or or a structure or or array into a couple of sub variables the after auto keyword you can actually put the ampersand to make it a reference or or our value reference and then there is a list list of identifiers between the square brackets and this actually depending on what type this this foo has in this case it's it's a tuple so it uses the tuple element and tuple size to determine the size the number of elements there and in this case it initializes three variables one will be in one will be long one float to those values of from from the tuple but it can when it's a structure for instance the requirement is that all the non non static data members are within the same same class or structure or in some base class but all of them have to be in the same in the same structure and all of them have to be public and in that case all the elements here are assigned in the in the order they appear in the structure if you have array then you assign basically those identifiers are not that in that case or variables but what references to those elements of the array and you can use those in the code later on inline variables is another thing which works kind like static variables inside of inline functions basically you can each each translation unit can have its own variable definition and all those definitions are put together into a single variable and the requirement is that they are initialized to the same well they're the same thing they have to have the same definition the main reason for adding inline variables was the problem with static constexpr static data members inside of structures because in C++ 14 and earlier if you write something like this this is only a declaration and so as long as you use the static data member in normal context you just use the value that's that's no problem but as long as you for instance take the address of the static data member then suddenly you need to have a definition and you need to have a definition in a single compilation unit so you need to put const int as be semicolon somewhere somewhere in a single translation unit so this is this is no longer true in C++ 17 because static data members which are constexpr are in C++ 17 implicitly inline variables and so this is actually a definition and not not a declaration declaration later on is accepted but but it's not really required and this means you can use it anywhere else constexpr if is another new feature in C++ 17 the requirement is that the condition actually is is a constexpr value so it has to be a Boolean which expands to either true or for false through the constexpr folding and the difference between normal if and if constexpr is that if you have some templates and so on in the then or else block then those are not instantiated if if the condition is true or false depending on which block it is so you can actually write well it has to be valid C++ code there but the statements are the C++ standard says they are discard and so basically they are parsed and but they are not actually instantiated and evaluated and so on another feature is basically a syntactic sugar for being able to declare variable inside if or switch or what else for I think no for now you know while while if and switch and what this does is basically as if you put a another scope around the whole if and declare the auto variable there and then you use it in the condition and but if you write it this way it makes it shorter and there is a single difference between writing it in a separate scope around if and that's that this variable is in the same scope as variables declared here and variables declared here right if you don't use the brackets around so if you if you declare here another variable with the same name and it's an error and if you declare it here it's an error as well because it's the same scope this one is probably more important for the various package maintainers C++ 17 finally removed the dynamic exception specification on functions so in C++ 98 and and later on you could say that this function throws int or any class or whatever and at at runtime there would be a checking whether if you throw in some exception there would be runtime checking whether the exception matches the dynamic specification and if not your program will be terminated so you can't write this anymore and the only thing that is still allowed is use those C++ 11 no accept or no accept and in the parents write true or false or some expression some Boolean expression this this one says whether the function can throw anything or can't it's just just what what you use most commonly basically you just say this function can't can't throw or can't throw and while throw in C++ 98 and so on was also a dynamic specification where where it said that the function can't throw anything and terminated the program if you throw something this throw is still accepted because it's it's used all around in all the headers like all the g-lipsy headers for most of the functions that can't actually throw an exception or be cancelled through p-thread cancellation just have this through some macro and it's it's used in many many headers this is still accepted but in C++ 17 it's it's an equivalent of saying no accept so it has slightly different behavior but for most most of use cases you really don't care but if you use throw with something else you need to rewrite it to just say just drop the throw another thing which which is very useful is that there are no new and delete operators which accept another argument the alignment and if you have some class or object which which needs big alignment uses vectors inside it or whatever then or uses align align as and such such attributes then then the compiler will as long as the as the alignment is bigger than than the default then the compiler will actually use these operators which which have the extra arguments so if you override the override the system library new delete you probably want to override the new operators as well and then just use POSIX MMLI or whatever function provides you a location with the alignment also and the requirement is that of course anything you allocate with the new with alignment with alignment argument that it has to be deleted with the same operator or corresponding operator another feature is is that C++17 added some requirements on the evaluation of operands GCC now has this new option which has three three possibilities it can be equals none equals some and equals all strong eval order equals all is is the full requirement of C++17 which means that there is a constraint on the member access array subscripting shift expressions and assignments and some is is just a subset I think it's shift expressions and member access and and none is is what what C++14 had basically everything is undefined the order is undefined it depends on the on the language which which which is chosen we still default to C++14 so the default is strong eval order sum so base shift expressions the reason why why this has changed is that many people write in C++ use the shift operators a lot and write huge expressions with them and really expect that the left side and right side are evaluated in some order but in C++14 the order is undefined and if you have some side effects between them no there are no warnings it's just about what what if the order is defined that side effect for instance if you have member access this means if you have something square bracket and some other expressions and square bracket then the left side evaluates first and and what is inside the square bracket the index evaluates after that if it has side effects or no another array subscripting member access is again if you have a dot B or a arrow B then a side effects evaluate first and then B and for shift expressions it's again left right first you evaluate the left operand of the shift and then right and well we have those what's the name of the sequence point warning there is but this just says that yeah that the order is is not undefined in that case and it is well defined for assignments you first evaluate the right side and then the left side which is yeah initially the C++ committee wanted to make also the order of arguments inside of a function defined so it would be left to right but after some analysis it was decided not to do this because some compilers emit arguments right to left and it's it's more efficient to do it that way and some other compilers do it the other way and it sometimes it depends on ABI and whether you have push pop and stuff like that so another extension is is that you can for non non-type arguments of templates you can actually use auto keyword so that it it's it can be an integer or it can be also autumn and asterix or something like that or auto reference and and so on yeah no there the C++ standards no they are they're undefined then the order if you have side effects in all of them yeah so the question was if yeah if it could if we could require for instance at least what left right or right left order I'm not on the C++ committee so that was something C++ committee decided well but one compiler will do this another compiler will do something else well I think in GCC it's right now driven on some back-end macro on the same system it's actually yeah that's that's what what GCC does but we are not going to guarantee it for you because it can change anytime it's it's better it's not too bright side effects in between function arguments but if you use the for instance the shift expressions the way most C++ folks use them now you have a guarantee because there were measurements and show that requiring left right order it was too slow and for some architectures and well the guarantees come from the C++ committee so that's their decision and what GCC does is it's it's always because GCC right now uses the Gimple as the first first intermediate language then we all already use some some order this way or that way because all the side effects have to be visible in the Gimple language and then there and then it's lower it's so so it's not like in the like 15 years ago when when it this was really dependent on on the details of the evaluation of the arguments but still still there is no guarantee from the committee so you really should not depend on the well well the well well C++ 17 requires defaults to strong ever order all so it requires all these for C it's not required so C C doesn't try to it actually in some cases this this order even this order slow stuff down because yeah yeah evaluate something for us then sometimes you can you have to use a temporary variable for something or sometimes you manage to optimize it away but sometimes you can anyway this is C plus plus let's let's go to some some of the new optimizations of course there are many changes to all the other optimizations so this is just the major major new optimizations one is store merging if you store constants in adjacent memory like and the fields are actually small small enough then sometimes it's worth to combine all the four stores in this case into a single store of a single constant where the store merging pass actually can can work also with bit fields and stuff like that or later on it can be extended also for some operations on bit you know on bit fields if you for instance use logical bitwise operations on all the bit fields then it can combine them into a single operation and so on then there are two two new bitwise two new interprocedural optimizations one is GCC in constant propagation actually computes also a bit mask which bits in each variable or value are known to be zero and many many optimizations can actually use this information to optimize for instance if you know the low low three bits of a pointer are known to be zero then you know the pointer is 8 bytes aligned or stuff like that and so we now propagate this information across the call graph so if some function is always called with with the values in the parameters which have zero in third and fifth bit then we can actually use it and so on and for a value range propagation we also propagate the value ranges if you know this this value has to be bigger than hundred and smaller than 200 then again if it's an argument passed to some function or returned from a function then we can optimize that another optimization is the loop splitting if you have a loop and inside that loop there is a condition and you have separate blocks depending on that condition and the condition is true or false for one one side of the iteration space and opposite for the rest of the iteration space then we can actually split it split it into two loops which which don't have to check the condition anymore code hoisting is this is not a new path optimization paths but just part of the partial redundancy elimination and code hosting tries to move evaluation x of expressions earlier into into path where we where we know the we will we will compute the expression later on and it usually decreases the code size quite a lot and otherwise sometimes it's also speech function but not always so another new feature in GCC is support for it var 5 which is going to be finally released after how many six and a half years or next month and this is implemented under Gdvar 5 it's not on by default because the consumers GDB and and other consumers are still getting the support or you would really need to have the latest utilities to consume the debug information so we will switch the default maybe in two years but for now if you want to use var 5 you can use this new option there are various GNU extensions which we have implemented over the years were actually accepted into the standard with some changes so that's what we have implemented for almost for free because it's what it was just renaming of stuff and so on the location and ranges sections were replaced replaced by sections where you actually can use fewer relocations and it can be actually smaller and so on there were some new tags and attributes for C++ 11 and 14 debug type sections were removed from the standard again and it's now a new kind of units inside of debug info and debug line section is now more variable you can actually specify what kind of fields you have to develop for the files another feature which has been already in GCC 6 and 5 but has been extended is OpenMP support and especially OpenMP offloading to GP GPUs and other offloading devices what is new in GCC 7 is that you can now offload OpenMP code to NVIDIA PTX and we actually this is the first offloading we actually package in Fedora so you can actually install two packages which are built on site with GCC and have to use the binary blob libcuda from somewhere else we just need to open it and then you can offload your code and compute it on the GP GPU for AMD there is there is support as well but we don't package it because the upstream kernel driver does not support what we need for that and for ZN5 I'm still looking for access to such hosts because I had access to KNL which is the main CPU of the processor but not the offloading card and the PCI card in the sanitizers some of the changes where that we now can actually at front time diagnose if you use variables load variables or store variables which are outside of their scope for instance you take address of some local automatic variable and after you leave the scope of the variable you actually de-reference the pointer and so that's undefined behavior in CC plus plus of course and and actually GCC has been optimizing that for quite some time but we didn't have any diagnostics of these bugs because GCC at the end of scope if the variable is addressable we put a clobber which is assigned to GCC that it can throw away all the stores to that location because it's going to be and it's going to be removed inside of destructor and so on and in teachers signed overflow diagnostics now diagnosis vectors as well and that's all I would like to say that GCC 7 landed into raw height yesterday so if your package is no longer built I would appreciate cooperation and just just file bugs if well you would appreciate if you could first analyze the those bugs yourself and if you find some issues which you believe are GCC bugs and not your package bugs then of course file file bugs either in our bugzilla or if it's upstream GCC it can be upstream GCC as well but because usually you know your package is better than then be it's it might be faster for you to debug issues if there are on the packages side and mark is actually performing a test master build the the master build actually has completed but there is some analysis still still ongoing so we will post some guide how to port your packages to GCC 7 which will also include all the warnings which we have listed and stuff like that any questions well the C standard basically says that the malloc should align everything on so that all the fundamental types of the language but we will those edit types are not part of the of the standard or they are yeah gray era so basically yeah you have to count with with the diff what what the gipsy does basically it guarantees you twice twice the size of the pointer as alignment if you use if you use vector types and stuff like that you should always use mem align post six align or C C 11 has aligned a lock or or in C++ 17 now you kiss you can use the new operator which will do it automatically but it's it's non-standards type so you have to do something on your own yes that's so that you can actually implement it even on architectures where malloc does not is not able to do it for instance if on hp ucs say you you don't have malloc which which can guarantee you any any extra alignment and if the default delete operator uses free then you basically have to have something which allocates you something that you can free and so what what would you do in that case you would try malloc as many times as possible until you get something aligned that's not going to work and so for instance for hp ucs the implementation allocates the size plus the alignment and stores the actual point returned by malloc into into word before the allocation and then the delete operation operator is different because it actually reads that word before the before the allocation and freeze that and not not itself not the other is passed by user and on windows you have also some aligned alloc and aligned free and you have to pair them another question last question well I would guess that people really don't don't use that because it doesn't make much sense pointer pointer equals one yeah it's well yeah maybe maybe it would be useful to work in that case too yeah maybe maybe it does the thing is that this is really common and it occurs also in GCC sources at some point in in various packages so people really make this kind of mistake and it actually compiles without warning and it compares the point against now