gcc - Ada 标签比较导致编译器崩溃
问题描述
我不确定这是否是我的 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 "");
而如果我将该主体更改为:
function Tag_To_String (From : Ada.Tags.Tag) return String is ("");
我得到的错误正是:
gcc -c -gnat12 sourcefile.adb
raised STORAGE_ERROR : stack overflow or erroneous memory access
gprbuild: *** compilation phase failed
知道为什么 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;
请注意,我已编辑代码以使用函数表达式。它仍然适用于 GNAT/GPS 2018 版本。这个版本是用 gprbuild -d -PD 编译的
推荐阅读
- vba - 包含范围的文本的 Excel 转换——数字到字母数字
- bash - Bash:错误报告流程突然将值从 1 更改为 0
- debian - 在 Beaglebone green 上交叉编译 debian
- python-3.x - python中一些简单列表和if语句的错误
- ios - 黑色导航栏覆盖集合视图标题中的图像视图
- java - 如何使用 Gradle 4.4 创建一个包含所有依赖项的 jar?
- python - 无法索引
- python - 从读取 csv 转换为 excel - pandas/python
- tfs - 将 Visio 文件附加到 TFS 2018 Wiki 页面
- asp.net-core - Razor Pages 路由技术