[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::c_plus_plus

Title:C++
Notice:Read 1.* and use keywords (e.g. SHOW KEY/FULL KIT_CXX_VAX_VMS)
Moderator:DECCXX::AMARTIN
Created:Fri Nov 06 1987
Last Modified:Thu Jun 05 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:3604
Total number of notes:18242

3566.0. "Does the "explicit" keyword disappeared ?" by BACHUS::SABLON (Mich�le Sablon, TP/IM Support Belgium 856-7238) Mon May 12 1997 14:01

C++ T5.6-6
Digital UNIX V4.0-B

	I've just installed the new 5.6 field test version and I'm trying to 
	rebuild a customer example. It had a number of problem but it seems
	the new version will bring some more ones.

	The first one met is during the compilation of a program. This one,
	which used to work, now failed with the following error message:

cxx: Error: /ctiv/dvlpt/application/common/utilities/translation/include/TrMess.
    explicit TrMessage(const CTIV_String &theDefinitionName) throw(ExcRoot);   B
-------------^

	It is like it doesn't like the syntax of "explicit" ! I've look through 
	the documentation and couldn't find a lot about it. Just a remark in the 
	VMS C++ documentation listing the "Explicit keyword" as an 
	incompatibility between DEC C++ and the "September 1995 ANSI C++ Draft".

	Is it also true on UNIX ? Why then does the program complied in earlier 
	C++ version ?

	Best,
	Mich�le.
T.RTitleUserPersonal
Name
DateLines
3566.1explicit has never worked in DEC C++, but will be in 6.0DECC::J_WARDMon May 12 1997 14:3018
"explicit" is a new keyword added into the ANSI C++
draft standard about a year ago. It is not currently nor has
it ever been supported in Digital C++. It will be supported in
V6.0.

BTW, what it means is that the constructor cannot be used
in standard conversions, it can ONLY be used as a constructor.

Anyone who is currently distributed libraries should have a workaround
for compilers that don't currently support non-converting
constructor syntax, i.e:

#ifdef __DECCXX // explicit not supported
#define	explicit	
#else
#define explicit explicit
#endif
3566.2DECC::OUELLETTEmudseason into blackfly seasonMon May 12 1997 14:3742
Perhaps this is a header file problem.
The 'explicit' keyword is reserved by the draft standard.
Since V5.6 implements something less than the draft standard,
but more than the ARM language, there may be something funny happening here.
I see that the current lex.c recognizes "explicit" as a keyword,
that may be new.

From the December 1996 draft...

7.1.2 paragraph 6:

	The explicit specifier shal be used only in declarations of
	constructors within a class declaration; see 12.3.1

12.3.1 paragraph 2:

	An explicit constructor constructs objects just like non-explicit
	constructors, but does so only where the direct-initialization
	syntax (8.5) or where casts (5.2.9, 5.4) are explicitly used.
	A default constructor may be an explicit constructor; such a
	constructor will be used to perform default-initialization (8.5)

... and an example.

An explicit ctor means you must use syntax like:

C c1;
C c2(1);
C c3 = C(1);
C *pc4 = new C(1);
C c5 = (C)1;
C c6 = static_cast<C>(1);

But this syntax is disallowed:

C c7 = 1;

What problem this adition to the language solves and if
V5.6 implements it or even tolerates the keyword in some reasonable
way is unknown to me.  Give me a moment to look...

R.
3566.3DECC::OUELLETTEmudseason into blackfly seasonMon May 12 1997 14:5325
Judy & I collided on our replies.
Here's a little test case I wrote confirming her answer.

cosf> cat explicit.cxx
class C {
  int member;
public:
  explicit C(int);
};

C c1 = 1;

cosf> cxx -c explicit.cxx		!! the 5.6 compiler
cxx: Error: explicit.cxx, line 4: Invalid declaration.
  explicit C(int);
-----------^


cosf> $CEXE/exx_driver -c explicit.cxx	!! the 6.0 compiler
cxx: Error: explicit.cxx, line 7: no suitable constructor exists to convert
from
 "int" to "C"
C c1 = 1;
-------^
1 error detected in the compilation of "explicit.cxx".
3566.4DECCXX::MITCHELLTue May 13 1997 10:153
Just to be clear, V5.5 and V5.6 behave the same
for this case.  The "explicit" keyword will be
supported in V6.0.
3566.5ThanksBACHUS::SABLONMich�le Sablon, TP/IM Support Belgium 856-7238Tue May 13 1997 10:298
    I've implemented the fix and its works. Discussing with the customer, it 
    appears that the code was effectively compiling in CXX 5.5 but the 
    successfull use of 'explicit' was dependent of unqualified conditions.

    Understand, sometimes it works, sometimes it doesn't, who knows why ?!

    Thanks in any case for help,
    Mich�le.