2392 – Parsing ambiguity between function pointer declaration and function call

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2392 - Parsing ambiguity between function pointer declaration and function call
Summary: Parsing ambiguity between function pointer declaration and function call
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 All
: P2 minor
Assignee: Walter Bright
URL:
Keywords: spec
: 3980 (view as issue list)
Depends on: 4987
Blocks: 3104
Show dependency tree / graph
Reported: 2008年10月04日 15:34 UTC by Walter Bright
Modified: 2014年02月15日 13:12 UTC (History)
3 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Walter Bright 2008年10月04日 15:34:17 UTC
The following code won't compile:
int function() foo(int i);
int* p;
void main() {
 foo(*p)();
}
because foo(*p)() looks like a C-style declaration of p being a pointer to a function that returns type foo. Too work around, add parentheses:
 (foo(*p)());
I can't see any way to fix this without dispensing with C style function pointer declarations.
Comment 1 Tomas Lindquist Olsen 2008年10月04日 17:41:17 UTC
> I can't see any way to fix this without dispensing with C style function pointer declarations.
Seems very reasonable to remove these to me
Comment 2 anonymous4 2008年10月09日 06:17:48 UTC
(In reply to comment #0)
> C-style declaration of p being a pointer to a
> function that returns type foo.
foo doesn't look like type to me, it's rather a forward declaration of a function. So compiler just needs to distinguish functions from types.
Comment 3 Stewart Gordon 2008年11月24日 10:17:14 UTC
That would be a dependency of parsing on semantic analysis, which is something D by design doesn't have.
I agree that C-style function pointer declarations should be thrown out, just as C-style cast syntax has been already.
Comment 4 Ellery Newcomer 2010年03月17日 13:11:43 UTC
*** Issue 3980 has been marked as a duplicate of this issue. ***
Comment 5 Walter Bright 2010年11月09日 19:46:40 UTC
The disambiguation rule for "is it a declaration or a statement" is resolved by the rule "if it looks like a declaration, it is a declaration". The behavior you're seeing is as designed.
Comment 6 Walter Bright 2010年11月09日 19:53:19 UTC
http://www.dsource.org/projects/phobos/changeset/2149 


AltStyle によって変換されたページ (->オリジナル) /