"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/dmd/semantic2.d" between
dmd-2.095.0.tar.gz and dmd-2.095.1.tar.gz

About: DMD (Digital Mars D) is the D reference compiler. D is an object-oriented, imperative, multi-paradigm system programming language.

semantic2.d  (dmd-2.095.0):semantic2.d  (dmd-2.095.1)
skipping to change at line 351 skipping to change at line 351
mod.userAttribDecl.semantic2(sc); mod.userAttribDecl.semantic2(sc);
} }
sc = sc.pop(); sc = sc.pop();
sc.pop(); sc.pop();
mod.semanticRun = PASS.semantic2done; mod.semanticRun = PASS.semantic2done;
//printf("-Module::semantic2('%s'): parent = %p\n", toChars(), parent); //printf("-Module::semantic2('%s'): parent = %p\n", toChars(), parent);
} }
override void visit(FuncDeclaration fd) override void visit(FuncDeclaration fd)
{ {
import dmd.dmangle : mangleToFuncSignature;
if (fd.semanticRun >= PASS.semantic2done) if (fd.semanticRun >= PASS.semantic2done)
return; return;
if (fd.semanticRun < PASS.semanticdone && !fd.errors)
{
/* https://issues.dlang.org/show_bug.cgi?id=21614
*
* Template instances may import modules that have not
* finished semantic1.
*/
fd.dsymbolSemantic(sc);
}
assert(fd.semanticRun <= PASS.semantic2); assert(fd.semanticRun <= PASS.semantic2);
fd.semanticRun = PASS.semantic2; fd.semanticRun = PASS.semantic2;
//printf("FuncDeclaration::semantic2 [%s] fd0 = %s %s\n", loc.toChars(), toChars(), type.toChars()); //printf("FuncDeclaration::semantic2 [%s] fd0 = %s %s\n", loc.toChars(), toChars(), type.toChars());
// Only check valid functions which have a body to avoid errors // Only check valid functions which have a body to avoid errors
// for multiple declarations, e.g. // for multiple declarations, e.g.
// void foo(); // void foo();
// void foo(); // void foo();
if (fd.fbody && fd.overnext && !fd.errors) if (fd.fbody && fd.overnext && !fd.errors)
{ {
OutBuffer buf1;
OutBuffer buf2;
// Always starts the lookup from 'this', because the conflicts with // Always starts the lookup from 'this', because the conflicts with
// previous overloads are already reported. // previous overloads are already reported.
alias f1 = fd; alias f1 = fd;
auto tf1 = cast(TypeFunction) f1.type; auto tf1 = cast(TypeFunction) f1.type;
mangleToFuncSignature(buf1, f1); auto parent1 = f1.toParent2();
overloadApply(f1, (Dsymbol s) overloadApply(f1, (Dsymbol s)
{ {
auto f2 = s.isFuncDeclaration(); auto f2 = s.isFuncDeclaration();
if (!f2 || f1 == f2 || f2.errors) if (!f2 || f1 == f2 || f2.errors)
return 0; return 0;
// Don't have to check conflict between declaration and definiti on. // Don't have to check conflict between declaration and definiti on.
if (f2.fbody is null) if (f2.fbody is null)
return 0; return 0;
// Functions with different manglings can never conflict
if (f1.linkage != f2.linkage)
return 0;
// Functions with different names never conflict
// (they can form overloads sets introduced by an alias)
if (f1.ident != f2.ident)
return 0;
// Functions with different parents never conflict
// (E.g. when aliasing a free function into a struct)
if (parent1 != f2.toParent2())
return 0;
/* Check for overload merging with base class member functions. /* Check for overload merging with base class member functions.
* *
* class B { void foo() {} } * class B { void foo() {} }
* class D : B { * class D : B {
* override void foo() {} // B.foo appears as f2 * override void foo() {} // B.foo appears as f2
* alias foo = B.foo; * alias foo = B.foo;
* } * }
*/ */
if (f1.overrides(f2)) if (f1.overrides(f2))
return 0; return 0;
auto tf2 = cast(TypeFunction) f2.type; auto tf2 = cast(TypeFunction) f2.type;
// extern (C) functions always conflict each other. // Overloading based on storage classes
auto parent1 = f1.toParent2(); if (tf1.mod != tf2.mod || ((f1.storage_class ^ f2.storage_class)
if (f1.ident == f2.ident && & STC.static_))
parent1 == f2.toParent2() && return 0;
parent1.isModule() &&
(f1.linkage != LINK.d && f1.linkage != LINK.cpp) && const sameAttr = tf1.attributesEqual(tf2);
(f2.linkage != LINK.d && f2.linkage != LINK.cpp) && const sameParams = tf1.parameterList == tf2.parameterList;
// But allow the hack to declare overloads with different pa // Allow the hack to declare overloads with different parameters
rameters/STC's /STC's
(!tf1.attributesEqual(tf2) || tf1.parameterList != tf2.param // @@@DEPRECATED_2.094@@@
eterList)) // Deprecated in 2020-08, make this an error in 2.104
if (parent1.isModule() &&
f1.linkage != LINK.d && f1.linkage != LINK.cpp &&
(!sameAttr || !sameParams)
)
{ {
// @@@DEPRECATED_2.094@@@
// Deprecated in 2020-08, make this an error in 2.104
f2.deprecation("cannot overload `extern(%s)` function at %s" , f2.deprecation("cannot overload `extern(%s)` function at %s" ,
linkageToChars(f1.linkage), linkageToChars(f1.linkage),
f1.loc.toChars()); f1.loc.toChars());
// Enable this when turning the deprecation into an error
// f2.type = Type.terror;
// f2.errors = true;
return 0; return 0;
} }
buf2.reset(); // Different parameters don't conflict in extern(C++/D)
mangleToFuncSignature(buf2, f2); if (!sameParams)
return 0;
auto s1 = buf1.peekChars(); // Different attributes don't conflict in extern(D)
auto s2 = buf2.peekChars(); if (!sameAttr && f1.linkage == LINK.d)
return 0;
//printf("+%s\n\ts1 = %s\n\ts2 = %s @ [%s]\n", toChars(), s1, s2 error(f2.loc, "%s `%s%s` conflicts with previous declaration at
, f2.loc.toChars()); %s",
if (strcmp(s1, s2) == 0) f2.kind(),
{ f2.toPrettyChars(),
error(f2.loc, "%s `%s%s` conflicts with previous declaration parametersTypeToChars(tf2.parameterList),
at %s", f1.loc.toChars());
f2.kind(), f2.type = Type.terror;
f2.toPrettyChars(), f2.errors = true;
parametersTypeToChars(tf2.parameterList),
f1.loc.toChars());
f2.type = Type.terror;
f2.errors = true;
}
return 0; return 0;
}); });
} }
if (!fd.type || fd.type.ty != Tfunction) if (!fd.type || fd.type.ty != Tfunction)
return; return;
TypeFunction f = cast(TypeFunction) fd.type; TypeFunction f = cast(TypeFunction) fd.type;
UserAttributeDeclaration.checkGNUABITag(fd, fd.linkage); UserAttributeDeclaration.checkGNUABITag(fd, fd.linkage);
//semantic for parameters' UDAs //semantic for parameters' UDAs
foreach (i, param; f.parameterList) foreach (i, param; f.parameterList)
 End of changes. 12 change blocks. 
40 lines changed or deleted 54 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)