Redeclaration with different type

65 views
Skip to first unread message

razvyb...@gmail.com

unread,
Jan 20, 2018, 11:10:45 AM1/20/18
to ISO C++ Standard - Discussion
Could you please tell me the section from the standard that forbids redeclarations with different types? An example would be (at global namespace/scope):

extern const int a;
extern int a;

I don't think there is a general rule for this type of redeclaration, as [basic.types] shows an example of a redeclaration with a different type (int[] to int[N]).

Thank you. 

Brian Bi

unread,
Jan 22, 2018, 5:16:05 PM1/22/18
to std-dis...@isocpp.org
[basic.link]/11

After all adjustments of types (during which typedefs are replaced by their definitions), the types specified by all declarations referring to a given variable or function shall be identical, except that declarations for an array object can specify array types that differ by the presence or absence of a major array bound ([dcl.array]). A violation of this rule on type identity does not require a diagnostic.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+unsubscribe@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.



--
Brian Bi

razvyb...@gmail.com

unread,
Jan 23, 2018, 7:32:25 AM1/23/18
to ISO C++ Standard - Discussion
Thank you! I asked this question somewhere else and the answer was [over]/1. Another user also mentioned the exception that allows a variable to have declarations with different types in the case the two types are array with/without bound.
Therefore the statement in [over]/1 is partially wrong. Thank you again!


On Tuesday, January 23, 2018 at 12:16:05 AM UTC+2, Brian Bi wrote:
[basic.link]/11

After all adjustments of types (during which typedefs are replaced by their definitions), the types specified by all declarations referring to a given variable or function shall be identical, except that declarations for an array object can specify array types that differ by the presence or absence of a major array bound ([dcl.array]). A violation of this rule on type identity does not require a diagnostic.
On Sat, Jan 20, 2018 at 8:10 AM, <razvyb...@gmail.com> wrote:
Could you please tell me the section from the standard that forbids redeclarations with different types? An example would be (at global namespace/scope):

extern const int a;
extern int a;

I don't think there is a general rule for this type of redeclaration, as [basic.types] shows an example of a redeclaration with a different type (int[] to int[N]).

Thank you. 

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org.

To post to this group, send email to std-dis...@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.



--
Brian Bi
Reply all
Reply to author
Forward
0 new messages