standardese | A nextgen Doxygen for C
kandi X-RAY | standardese Summary
kandi X-RAY | standardese Summary
The nextgen Doxygen for C++. Standardese aims to be a nextgen Doxygen. It consists of two parts: a library and a command line tool. The library aims at becoming the documentation frontend that can be easily extended and customized. It parses C++ code with the help of libclang and provides access to it. The tool drives the library to generate documentation for user-specified files. It supports a couple of output formats including Markdown and HTML as well as experimental Latex and Man pages. Read more in the introductory blog posts.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of standardese
standardese Key Features
standardese Examples and Code Snippets
Community Discussions
Trending Discussions on standardese
QUESTION
...Calling a function through an expression whose function type is different from the function type of the called function's definition results in undefined behavior.
ANSWER
Answered 2021-Jan-12 at 14:48C++14 had a weaker requirement, from [expr.call]/6:
[...] Calling a function through an expression whose function type has a language linkage that is different from the language linkage of the function type of the called function's definition is undefined ([dcl.link]). [...]
However [expr.reinterpret.cast]/6 contained a similar, but stronger requirement:
A function pointer can be explicitly converted to a function pointer of a different type. The effect of calling a function through a pointer to a function type ([dcl.fct]) that is not the same as the type used in the definition of the function is undefined.
P0012R1 made exception specifications to be part of the type system, and was implemented for C++17
The exception specification of a function is now part of the function’s type:
void f() noexcept(true);
andvoid f() noexcept(false);
are functions of two distinct types. Function pointers are convertible in the sensible direction. (But the two functionsf
may not form an overload set.) This change strengthens the type system, e.g. by allowing APIs to require non-throwing callbacks.
and moreover added [conv.fctptr]:
Add a new section after section 4.11 [conv.mem]:
4.12 [conv.fctptr] Function pointer conversions
A prvalue of type "pointer to noexcept function" can be converted to a prvalue of type "pointer to function". [...]
but included no changes to [expr.reinterpret.cast]/6; arguably an unintentional omission.
CWG 2215 highlighted the duplicated information in [expr.call] compared to [expr.reinterpret.cast]/6, flagging the weaker requirement in the former as redundant. The following cplusplus / draft
commit implemented CWG 2215, and removed the weaker (redundant) requirement, made [expr.reinterpret.cast]/6 into a non-normative note and moved its (stronger) normative requirement to [expr.call]; eventually this stronger requirement was broken out into its own paragraph.
This confusion arguably lead to the unintentional (seemingly conflicting) rules that:
- a prvalue of type “pointer to
noexcept
function” can be converted to a prvalue of type “pointer to function” ([conv.fctptr]/1), and - calling a function through an expression whose function type is different only by its exception specification is undefined behaviour.
Afaict, there are no defect reports covering this issue, and a new one should arguably be submitted.
QUESTION
(This is a follow up to this question.)
So I'd like to ask question specifically to understand the standardese quoted in that answer I received, and my exact question is in the title.
Honestly, not even on cppreference I understand what the reason is why the standard says so.
However, here's the minimal example:
...ANSWER
Answered 2020-Dec-10 at 17:55It does not compile because a contexpr
reference has to bind to an global variable object with static storage duration. Your reference is binding to a local variable so it is not constexpr
and cannot be used to initialize another constexpr
variable.
By removing the reference you initialize a 2nd array with the first one, which is a valid constexpr
.
EDIT: I did not notice the language lawyer tag and do not have a copy of the C++ standard to quote, so feel free to answer if you do.
QUESTION
I stumbled across a difference in behavior between different compilers. Suppose the following code:
...ANSWER
Answered 2020-Aug-07 at 15:00failbit
should be set. It's done by sentry
object, what ws
constructs first thing.
[istream::sentry]/2
explicit sentry(basic_istream& is, bool noskipws = false);
Effects: Ifis.good()
isfalse
, callsis.setstate(failbit)
. Otherwise, ...
QUESTION
I was trying to do something similar to this:
...ANSWER
Answered 2019-Jan-23 at 18:29int*
is a "derived declarator type"(not a standard term, but useful for reasoning about this). A functional style cast notation (which is what int(2)
is) can only contain a "A simple-type-specifier or typename-specifier". A derived declarator type doesn't fall under either category.
You have to either:
write it out in the form of a C-style cast:
QUESTION
I've been looking for standardese on this all evening, with no luck. Perhaps I'm missing something!
In the following code example, is the copy into uint32_t a
sequenced with the the copy into uint32_t b
during the assignment *one = *two
, or is this implementation defined?
ANSWER
Answered 2018-Nov-02 at 12:04The C standard does not define ordering for assignment of members within a structure when assigning a structure.
About assignment, C 2018 6.5.16.1 says only:
2 In simple assignment (
=
), the value of the right operand is converted to the type of the assignment expression and replaces the value stored in the object designated by the left operand.3 If the value being stored in an object is read from another object that overlaps in any way the storage of the first object, then the overlap shall be exact and the two objects shall have qualified or unqualified versions of a compatible type; otherwise, the behavior is undefined.
Examining the standard for all mentions of “member”, “struct”, or “structure” does not reveal anything that would impose any chronological ordering on the members within the assignment. (There is not even an explicit definition of what the value of a structure is; we are left to presume it is effectively an ordered tuple of the value of its members, or perhaps, from “a structure is a type consisting of a sequence of members” in 6.7.2.1 6, that its value is a sequence of values of its members.)
QUESTION
We have the following simple (and slightly modified to add main
and output) example in the Standard:
ANSWER
Answered 2018-Oct-29 at 15:56A using declaration, while indeed a declaration as far as declarative regions are concerned, is not a function declaration. We can see it specified grammatically:
[dcl.dcl]
1 Declarations generally specify how names are to be interpreted. Declarations have the form
QUESTION
Had a compliation issue recently, illustrated by this snippet:
...ANSWER
Answered 2018-Oct-05 at 13:52clang is correct here. Filed 87530.
The rule for return statements is [class.copy.elision]/3:
In the following copy-initialization contexts, a move operation might be used instead of a copy operation:
- If the expression in a
return
statement ([stmt.return]) is a (possibly parenthesized) id-expression that names an object with automatic storage duration declared in the body or parameter-declaration-clause of the innermost enclosing function or lambda-expression, or- if the operand of a throw-expression is the name of a non-volatile automatic object (other than a function or catch-clause parameter) whose scope does not extend beyond the end of the innermost enclosing try-block (if there is one),
overload resolution to select the constructor for the copy is first performed as if the object were designated by an rvalue. If the first overload resolution fails or was not performed, or if the type of the first parameter of the selected constructor is not an rvalue reference to the object's type (possibly cv-qualified), overload resolution is performed again, considering the object as an lvalue. [ Note: This two-stage overload resolution must be performed regardless of whether copy elision will occur. It determines the constructor to be called if elision is not performed, and the selected constructor must be accessible even if the call is elided. — end note ]
Emphasis mine.
We meet the first bullet, we're returning an id-expression that names a non-volatile automatic object. So we perform overload resolution as if it were an rvalue. This overload resolution succeeds, there is a constructor that takes a Base&&
. However, note the bolded part. The type of this parameter is not an rvalue reference to the object's type.
Hence, we try again consider the object as an lvalue. This overload resolution fails.
As a result, the program is ill-formed.
QUESTION
Why are structured bindings defined through a uniquely named variable and all the vague "name is bound to" language?
I personally thought structured bindings worked as follows. Given a struct:
...ANSWER
Answered 2018-Apr-12 at 13:42Structured binding exists to allow for multiple return values in a language that doesn't allow a function to resolve to more than one value (and thus does not disturb the C++ ABI). The means that whatever syntax is used, the compiler must ultimately store the actual return value. And therefore, that syntax needs a way to talk about exactly how you're going to store that value. Since C++ has some flexibility in how things are stored (as references or as values), the structured binding syntax needs to offer the same flexibility.
Hence the auto &
or auto&&
or auto
choice applying to the primary value rather than the subobjects.
Second, we don't want to impact performance with this feature. Which means that the names introduced will never be copies of the subobjects of the main object. They must be either references or the actual subobjects themselves. That way, people aren't concerned about the performance impact of using structured binding; it is pure syntactic sugar.
Third, the system is designed to handle both user-defined objects and arrays/structs with all public members. In the case of user-defined objects, the "name is bound to" a genuine language reference, the result of calling get(value)
. If you store a const auto&
for the object, then value
will be a const&
to that object, and get
will likely return a const&
.
For arrays/public structs, the "names are bound to" something which is not a reference. These are treated exactly like you types value[2]
or value.member_name
. Doing decltype
on such names will not return a reference, unless the unpacked member itself is a reference.
By doing it this way, structured binding remains pure syntactic sugar: it accesses the object in whatever is the most efficient way possible for that object. For user-defined types, that's calling get
exactly once per subobject and storing references to the results. For other types, that's using a name that acts like an array/member selector.
QUESTION
Suppose we have the following code:
...ANSWER
Answered 2017-Aug-21 at 07:32The term "forwarding reference" is described at [temp.deduct.call/3](from C++17 draft n4659):
A forwarding reference is an rvalue reference to a cv-unqualified template parameter that does not represent a template parameter of a class template (during class template argument deduction).
In your example Container
is not a template parameter, it is a type you comprised from the template parameters T
and Container
. In order for the reference to be truly forwarding, you can use T&&
only. While Conatiner
is a template parameter, you can't have a reference to a template (the above paragraphs even mentions it explicitly). The type Container
is not the same as the template Container
. It's an instantiated class.1
While you can use SFINAE to obtain a forwarding reference that can be bound only to the container type, I personally feel you're better off just overloading the function.
QUESTION
I've got this short snippet of code that I'd like to get a bit more information about as to why overload resolution is picking one constructor over another. Here's the code in question:
...ANSWER
Answered 2017-Jul-27 at 19:03The reason that the code snippet in question compiles is due to non-standard conforming behavior from Visual Studio (I'm currently using VS2017.3 Preview, which compiles the code without errors even with the /permissive- flag). Below is the error emitted by GCC and Clang:
GCCCommunity Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install standardese
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page