Rule 14–6–1 and injected-class-names - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18) +--- Forum: MISRA C++:2008 rules (https://forum.misra.org.uk/forumdisplay.php?fid=19) +---- Forum: 6.14 Templates (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=142) +---- Thread: Rule 14–6–1 and injected-class-names (/showthread.php?tid=544) |
Rule 14–6–1 and injected-class-names - James Widman - 03-07-2008 Hi all, Rule 14–6–1 says: "In a class template with a dependent base, any name that may be found in that dependent base shall be referred to using a qualified-id or this->" But then the example code contains this line: Code: typename B::TYPE t2 = 0; // Compliant - explicit use base TYPE Code: typename ::B::TYPE t2 = 0; // Compliant - explicit use of B and of TYPE. Here's an example where it makes a difference: Code: template Re: Rule 14–6–1 and injected-class-names - James Widman - 07-07-2008 For what it's worth, at least one implementation binds the call 'B::j()' to ::N::B::j() in the instantiation of ::A::f2(), but it should bind to ::B::j(). So it seems pretty clear that we need to regard the use of 'B' in f2() as non-compliant. Also, since submitting the above post, I've found that some popular implementations don't correctly handle the uses of injected-class-names in the class template A above, so MISRA may want to say something about that. For example, MISRA may want to say that the 'safe' way to refer to a base class within a derived class involves a member typedef name; e.g.: Code: struct D : public N::B { Re: Rule 14–6–1 and injected-class-names - richard_corden - 16-07-2008 I agree. The example should probably be changed to: Code: typename A::B::TYPE t2 = 0; // Compliant - explicit use of B and of TYPE. and for simplicity even: Code: typename A::B::TYPE t2 = 0; // Compliant - explicit use of B and of TYPE. 'A' and 'A' match the current specialization. The rule text (or at least rationale) should be updated to highlight that this is required. Regards, Richard Re: Rule 14–6–1 and injected-class-names - misra cpp - 11-10-2016 A future edition or Technical Corrigendum will consider changes along the lines suggested by Richard Corden's post |