Lam*_*eta 1 gcc ada segmentation-fault gnat
我不确定这是我的gcc(4.8.5)或gprbuild(2.2.0)版本中的错误,但是当我尝试编译项目时,有一个特定的函数,其主体导致编译器崩溃STORAGE_ERROR.当我构建时,-cargs -v我看到这gnatl -quiet ...是崩溃前最近输出的命令.
所讨论的函数从属于特定类型层次结构的标签产生信息性字符串.它看起来像:
function Tag_To_String (From : Ada.Tags.Tag) return String is (
if From = A'Tag then "This is tag A"
elsif From = B'Tag then "This is tag B"
-- ...
elsif From = Z'Tag then "This is tag Z"
else "");
Run Code Online (Sandbox Code Playgroud)
如果我将该主体更改为:我可以成功编译它:
function Tag_To_String (From : Ada.Tags.Tag) return String is ("");
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
gcc -c -gnat12 sourcefile.adb
raised STORAGE_ERROR : stack overflow or erroneous memory access
gprbuild: *** compilation phase failed
Run Code Online (Sandbox Code Playgroud)
知道为什么gcc似乎无法编译这个特定的功能?
以下程序使用2018版本的GNAT和GPS正常工作.
with Ada.text_IO; use Ada.Text_IO;
with Ada.Tags; use Ada.Tags;
procedure Tag_Main is
package foo is
type A is tagged private;
type B is tagged private;
private
type A is tagged null record;
type B is tagged null record;
end foo;
use Foo;
function Tag_To_String(From : Ada.Tags.Tag) return String is(
if From = A'Tag then
"This is tag A"
else
"This is tag B"
);
begin
Put_Line(Tag_To_String(A'Tag));
Put_Line(Tag_To_String(B'Tag));
end Tag_Main;
Run Code Online (Sandbox Code Playgroud)
请注意,我已编辑代码以使用函数表达式.它仍适用于GNAT/GPS 2018版本.这个版本是用gprbuild -d -PD编译的