Error Message Missing

P

Peter Olcott

Yesterday I found that an invocation of a member function that
lacked the required "()" pararenthesis did not generate an error
message. This was an invocation of a member function that is part
of a library so I do not have access to the source code. The
compiler was MSVC++ 6.0.

I can't think of any scenario that would prevent a compiler error
message from being generated. Can some one please explain
how this could have occurred?
 
D

Dietmar Kuehl

Peter said:
Yesterday I found that an invocation of a member function that
lacked the required "()" pararenthesis did not generate an error
message. This was an invocation of a member function that is part
of a library so I do not have access to the source code. The
compiler was MSVC++ 6.0.

You mean something like below?

| struct foo
| {
| void bar() {}
| };
|
| int main()
| {
| foo f;
| f.bar; // <--- note this line!
| }

I guess you have something like the highlighted line: well,
this is effectively a valid expression which determines a
pointer-to-member-function and discards it unused. The
compiler on the system I'm currently using issues this
message:

| "tst.cpp", line 9: Warning: The value of <expression>.foo::bar
| is unused.

(plus a warning about the uninitialized 'f' but this is
irrelevant to this discussion).

It is possible to make the warning go away by actually using
the value, e.g. by assigning it to a pointer-to-member-function:

| void (foo::*ptmf)() = f.bar;
I can't think of any scenario that would prevent a compiler error
message from being generated. Can some one please explain
how this could have occurred?

I'd guess that the discussion above gives an indication why
the compiler did not issue an error. It might have issued a
warning, though. It is quite similar to a problem I
encountered recently where are program caused real damage
because it executed code it should not have executed under
the given conditions. It turned out that the code was
protected by something like this:

| if (some_condition)
| std::exit;

It's nice to mention the function 'std::exit()'. It would have
been nicer to actually execute it by tagging on parenthesis.
 
M

msalters

Dietmar said:
You mean something like below?

| struct foo
| {
| void bar() {}
| };
|
| int main()
| {
| foo f;
| f.bar; // <--- note this line!
| }

I guess you have something like the highlighted line: well,
this is effectively a valid expression which determines a
pointer-to-member-function and discards it unused.

No, it isn't. 5.3.1/3
"A pointer to member is only formed when an explicit & is used
and its operand is a qualified-id not enclosed in parentheses."

I don't understand how the poster knows the () is lacking when
he doesn't have the source code! You can't see it in a decompiled
binary.
| void (foo::*ptmf)() = f.bar;

Extension, should be a warning.
It is quite similar to a problem I
encountered recently where are program caused real damage
because it executed code it should not have executed under
the given conditions. It turned out that the code was
protected by something like this:

| if (some_condition)
| std::exit;

It's nice to mention the function 'std::exit()'. It would have
been nicer to actually execute it by tagging on parenthesis.

Not a member function, so this effectively is a (converts to)
pointer-to-plain-function. See 4.3

Regards,
Michiel Salters
 
R

Rolf Magnus

msalters said:
I don't understand how the poster knows the () is lacking when
he doesn't have the source code!

He doesn't have the source code of the function, but that doesn't mean that
he also doesn't have the source code of the call. However, I don't see how
the source of the function could be relevant.
 
P

Peter Olcott

Here is the actual code that erroneously
produces no errors on MSVC++ 6.0

class C {
public:
void length();
void length (int);
};
void C::length() {
}
void C::length(int f) {
}
int main() {
C myC;
return myC.length;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top